c - Error in string initialisation -


here trying out following thing in code , got following error---"prog.c:10:8: error: incompatible types when assigning type ‘char[100]’ type ‘char *’". please , tell me how can modify initialisation char str[100] right answer

#include <stdio.h> #include <stdlib.h>   int main() {    char str[100];     str = "a";   str = str + 1;   str = "b";   str = str + 1;   str = "c";   str = str + 1;    printf("%s", str - 2);   return 0;     } 

you have declared array

char str[100]; 

by specifying name of array base address of array same address of first element.

str="a"; 

in above statement, trying assign "a"s (note "a" string here) address array base. compiler not allow this. cos, if so, lose 100 elements.

if want assign first element value 'a', do

str[0] = 'a'; 

note have used single quote. remember "single quote single char".


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -