课上程序的补充

#include<stdio.h>
#include<string.h>
int main()
{
    void funstr(char a[]);
    char str[]="hello world";
    str[0]-=32;
    str[6]-=32;
    funstr(str);
 } 
void funstr(char a[])
{
    char *p;
    p=a;
    int n;
    n=strlen(a);
    while(n)
    {
        printf("%c",*p);
        p++;
        n--;
    }
    printf("\n");
    printf("%s\n",a);
}
Hello World
Hello World

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

总结:

1、课上写的跟以上程序差不多,只有变换字母大小写不一样,我本来想用for循环,如果数组遇到空格,就让它下一个字符减32,但是字符串本身最后的会有系统默认的‘\0’,导致程序一直出错,不能运行。

2、有查百度,但是并没有跳过空格让下一个字符变大写的办法,只能直接改变字符了。

posted on 2017-03-30 17:42  入骨温  阅读(121)  评论(0编辑  收藏  举报

导航