I am trying to copy name array to another array and print it
#include <stdio.h>
typedef struct
{
char name[100];
int age;
} data;
int main() {
char new_array[100];
data people[] = {{ "john", 12},{" kate", 15}};
for(int i =0; i < sizeof(people); i++) {
new_array[i] = people[i].name;
printf("%c ", new_array[i]);
}
return 0;
}
But it gives me an error:
error: assignment to ‘char’ from ‘char *’ makes integer from pointer without a cast [-Werror=int-conversion]
new_array[i] = people[i].name;
^
How do I fix this?
strcpyand What is a String in C may be handy. This has more to do with copying a string (strcpy/strncpy) than copying array contents (memcpy). Also, a semantic name likeperson_namemay be more helpful thannew_array.