Last active
June 14, 2021 07:23
-
-
Save emadflash/43e4589a471971947e69d7c91109374c to your computer and use it in GitHub Desktop.
print arrays LUL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
typedef enum { | |
INT, | |
CHAR, | |
} type; | |
void print_arr(void *arr, int size, type t) { | |
printf("[ "); | |
switch(t) { | |
case INT: | |
for(int i=0; i < size; ++i) { | |
printf("%d ", *((int*)arr + i)); | |
} | |
break; | |
case CHAR: | |
for(int i=0; i < size; ++i) { | |
printf("%c ", *((char*)arr + i)); | |
} | |
break; | |
default: | |
break; | |
} | |
printf(" ]"); | |
} | |
int main() { | |
int a[] = { 1, 2, 3, 4, 5, 6, 7 }; | |
char string[] = { 'f', 'u', 'c', 'k', 'y', 'o' ,'u' }; | |
print_arr(a, 7, INT); | |
printf("\n"); | |
print_arr(string, sizeof(string), CHAR); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment