I am having a hard time understanding how exactly are we allowed to play around with strings in c.
At class we were told that: - If we use the definition:
char *str="I love dogs";
we are NOT allowed to change the content of the string, and writing:
str[0]='W'
will result in an error. - If we use the definition:
char str[N]="I love dogs";
we are allowed to change the content of the string.
Will the functions in , for example strcpy, work in either case? Because I think I have seen an example where it worked.
Can anyone please explain when exactly can I change the content of a string, and why? Because now when I try to work with a string I have no idea what I am allowed to do and what not.
EDIT: Another thing, if we have:
char str[N]="I love dogs";
and we do something like
char *str2=str;
will we be able to change str2?
Thanks a lot.