Hi
I need to convert a string to char array in c? How can i do this
or atleast tell me how to extract a single char from string as incremental in next ???
Thanks in advance
Hi
I need to convert a string to char array in c? How can i do this
or atleast tell me how to extract a single char from string as incremental in next ???
Thanks in advance
In C, there's no (real, distinct type of) strings. Every C "string" is an array of chars, zero terminated.
Therefore, to extract a character c at index i from string your_string, just use
char c = your_string[i];
Index is base 0 (first character is your_string[0], second is your_string[1]...).
Hi there,
In C, a string is actually stored as an array of characters, so the 'string pointer' is pointing to the first character. For instance,
char myString[] = "This is some text";
You can access any character as a simple char by using myString as an array, thus:
char myChar = myString[6];
printf("%c\n", myChar); // Prints s
Hope this helps! David