课上作业补充

 

课上输出了Hello World,但是只是将字符串的h和w直接替换成了H和W,funstr函数是错误的

#include<stdio.h>
void funstr(char *str)
 {
     *str=*str-32;
     while(*str!='\0')
     {
         if(*str==32)
         *(str+1)=*(str+1)-32;
         printf("%c",*(str++));
     }
 }
int main()
{
    char str[]={"hello world"};  
    funstr(str);
printf("%s",str); }

运行结果:

Hello WorldHello World
--------------------------------
Process exited after 0.1232 seconds with return value 0
请按任意键继续. . .

总结:定义一个字符串str,定义一个funstr函数,将小写转化为大写,用%c输出,最后再用%s输出一遍

 

posted @ 2017-03-31 14:33  三途河岸  阅读(113)  评论(0编辑  收藏  举报