I am working on a practice problem that asks me to remove the first character in a string. Ex. char *string = "Rudolph", after calling removeFirst(string), string now equals "udolph".
I noticed, if I do it all in my main, I get the output "udolph". Here is my code:
int main() {
char *string = "Rudolph";
printf("%s\n", string);
//removeFirst(string);
string++;
printf("%s\n", string);
return 0;
}
However, if I were to call another function, my output is Rudolph. Here again is my code:
void removeFirst(char *string) {
if (string == "" | string == NULL)
return;
string++;
}
int main() {
char *string = "Rudolph";
printf("%s\n", string);
removeFirst(string);
//string++;
printf("%s\n", string);
return 0;
}
Given that I'm working with pointers, I thought that the changes I make in removeFirst should also make it to main. Why doesn't it work that way?