0
What is missing in this code which causing error and how to resolve this error??
#include <stdio.h> int main() { char arr[10]; arr="word"; printf("%s",arr); return 0; }
3 odpowiedzi
+ 2
You can't assign a string literal to a char array that already exist.
Either you do it directly:
char arr[10]="word";
Or you use the strcmp function from string.h.
Or you do it by hand, letter by letter with a loop, writing a 0/'\0' at the end.
+ 1
Either use char are[10]="xyz"
Or use strcpy(are[10], "xyx") with library of #include<string.h>
0
Actually when you are writing arr="word", its logically incorrect. Actually arr denotes the address of the first element of your array and it does not represent your array. So you should write char arr[10]= "word", thus initializing at the time of declaration. This will work. Kudos..