这是我的主要内容:
int main(void)
{
char w1[] = "Paris";
ChangeTheWord(w1);
printf("The new word is: %s",w1);
return0;
}
我需要在这个函数中更改
w1[]
的值:ChangeTheWord(char *Str)
{
...
}
最佳答案
int main()
{
char w1[]="Paris";
changeWord(w1); // this means address of w1[0] i.e &w[0]
printf("The new word is %s",w1);
return 0;
}
void changeWord(char *str)
{
str[0]='D'; //here str have same address as w1 so whatever you did with str will be refected in main().
str[1]='e';
str[2]='l';
str[3]='h';
str[4]='i';
}
也阅读 this 答案
关于c - 如何改变char指针的值?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22219933/