Skip to content

Instantly share code, notes, and snippets.

@emadflash
Last active June 14, 2021 07:23
Show Gist options
  • Save emadflash/43e4589a471971947e69d7c91109374c to your computer and use it in GitHub Desktop.
Save emadflash/43e4589a471971947e69d7c91109374c to your computer and use it in GitHub Desktop.
print arrays LUL
#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