课上程序的补充
#include<stdio.h> int funstr(char str[])//函数的声明 {int i=0;//定义 str[0]='H';//变换 str[6]='W';//变换 while(str[i]!='\0')//用while完成输出 {printf("%c",str[i]); i++; } } int main() {char str[]="hello world";//定义字符串 printf("%s\n",str);//打印 funstr(str);//调用函数 return 0; }
hello world Hello World -------------------------------- Process exited after 0.9151 seconds with return value 0 请按任意键继续. . .
总结:输出字符串时,要使用str而不是str[],调用函数时,也是如此,字符串最后一个为'\0'。
课上时调用的是funstr(str[]);课下通过多次实践,查找书上254到255的调用函数。