首页 > 其他 > 详细

课上程序的补充

时间:2017-03-30 19:22:38      阅读:232      评论:0      收藏:0      [点我收藏+]
#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、有查百度,但是并没有跳过空格让下一个字符变大写的办法,只能直接改变字符了。

课上程序的补充

原文:http://www.cnblogs.com/ruguwen/p/6647332.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!