I have just started learning pointers, and after much adding and removing *
s my code for converting an entered string to uppercase finally works..
#include <stdio.h>
char* upper(char *word);
int main()
{
char word[100];
printf("Enter a string: ");
gets(word);
printf("\nThe uppercase equivalent is: %s\n",upper(word));
return 0;
}
char* upper(char *word)
{
int i;
for (i=0;i<strlen(word);i++) word[i]=(word[i]>96&&word[i]<123)?word[i]-32:word[i];
return word;
}
My question is, while calling the function I sent word
which is a pointer itself, so in char* upper(char *word)
why do I need to use *word
?
Is it a pointer to a pointer? Also, is there a char*
there because it returns a pointer to a character/string right?
Please clarify me regarding how this works.