I have a function with the signature
char * processString(const char * const string);
This function is passed a constant pointer to a constant string defined in main()
int main(void) {
myString[] = "Hello";
char * ptr = processString(myString);
}
Inside processString() I want to iterate over each character, but I am stuck at grabbing the first character from this const pointer to const string.
I read this somehow related post (among others) c syntax passing const pointer to const data to function
I tried initializing a second pointer to read each character of the string one by one
char * processString(const char * const string) {
char * pointer = &string;
return pointer;
Your help is very much appreciated!
const-ness of the string is related to it?char *pointer = stringwhich should be the first character, I think. Although I am not sure because I didn't fully understand pointers yet.const string. The pointer is passed by value, so the function cannot modify the original pointer, anyway. See for example Use of 'const' for function parameters and Const correctness for value parameters.