I am trying to read a string from a keyboard and store it in a character pointer. But it doesn't seem to work. Can someone please help me out. Here is the code.
char *city = "Bangalore";
char *state;
state = city;
printf("Enter your state : ");
scanf("%s",state); // I get Bad access here.
but doesn't crash when I use this.
char city[] = "Bangalore";
char *state = city;
printf("Enter your state : ");
scanf("%s",state);