Sunday, 8 September 2013

Manipulate Character array as string in c

Manipulate Character array as string in c

I have read that storing a string in a character array(with null
termination) allows the string to be manipulated later on (unlike having a
pointer to string literal).
include
int main()
{char s[10]="Stack";
s[9]='a'; // a gets stored in array and if index is less than 6 string
gets changed
printf("%s\n",s);
return 0;
} Output : Stack
This works as long as index to be manipulated is less than length of string.
That means the string contents (and hence size) can't be changed even if
there is empty space?
Is there any direct way(not using functions) to add 'a' at the position
desired?

No comments:

Post a Comment