课上程序的补充

#include"stdio.h"
#include"string.h"
int main()
{
    void funstr(char str[]);
    char str[]="hello world";
    str[0]='H';
    str[6]='W';
    printf("%s\n",str);
    funstr(str);
   
 } 
 void funstr(char str[])
 {
     int i;
     i=0;
     while(str[i]!='\0')
     {
         printf("%c\n",str[i++]);
         }
     }

运行结果:

Hello World
H
e
l
l
o

W
o
r
l
d

--------------------------------
Process exited after 0.397 seconds with return value 0
请按任意键继续. . .

 

总结:在课堂上没有对i 赋予初值,大小写可以转换,但是一直显示程序出错,下次要注意定义一个整型,弄清楚函数的形式和要求。

posted @ 2017-03-30 23:31  voyageur  阅读(105)  评论(0编辑  收藏  举报