+ 1
Why it's comes to error?
#include<stdio.h> int main(){ char ch[20]; ch="study To night"; printf("%s",ch); }
5 Réponses
+ 4
String assignment does not exist in th C language,
You can use void strcpy(char str1[], char str2[]) from string.h.
This is equal to str1=str2 in C++;
So in your case :
strcpy( ch, "study to night");
Don't forget including <string.h>
+ 4
String is not assignable to ch this is invalid . You need to use strcpy .
Or you can do this if you want to print your string
#include<stdio.h>
int main(){
char ch[20]="study To night";
printf("%s",ch);
}
0
It will give you an error because you are trying to assign a string "literally" to a char array, C doesn't support that. But you can assign it to a char* (well because it is a pointer, not an allocated memory of chars). So this is allowed,
char *s;
s = "study To night";
And it becomes a string literal which you can't modify directly.