+ 1
What is the difference
At this code Why does he uses strcpy ? Why cant i just say test.str='hello'. ? https://code.sololearn.com/cWDXqJjWStN9/?ref=app
1 Answer
+ 3
"hello" is an array of characters in C.
str is also an character array.
In C, you cannot simply assign one array to another. You have to copy it element by element.
The string library <string.h> contains a function called strcpy does this task.
So you need to strcpy function.
char str[100];
strcpy(str, "hello");
// test.str = "hello"; is returns error.