我刚开始学习指针,经过很多次添加和删除 *
,我编写的将输入的字符串转换为大写的代码终于成功了。
#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;
}
我的问题是,在调用我发送的函数时,我发送了一个指针
word
,那么在char* upper(char *word)
中,为什么需要使用*word
?这是指向指针的指针吗?此外,char*
是否存在是因为它返回指向字符/字符串的指针呢?请向我说明其工作原理。
word
参数更改为upper
或本地变量word
的名称。 - Mattoupper
函数? - Some programmer dude