首页 > 代码库 > 课上程序的补充
课上程序的补充
#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、有查百度,但是并没有跳过空格让下一个字符变大写的办法,只能直接改变字符了。
课上程序的补充
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。