我刚开始学习的指针,并经过大量添加和删除*
我的代码,用于将输入的字符串转换为大写最终工程..通过函数传递字符串(C编程)
#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*
是因为它返回一个指向字符/字符串的指针吗?请澄清我如何工作。
我很困惑你在问什么。你问为什么它是上层(字符*字)而不是上层(字符字)? – Corbin 2011-12-17 13:46:19
函数upper请求一个指针作为参数,并提供一个指针(word)。就我所知,这是正确的。 – 2011-12-17 13:47:26
为了避免混淆,请在代码中将'word'参数的名称更改为'upper'或局部变量'word'。 – Mat 2011-12-17 13:47:57