C學的着實不怎么好,簡單粗暴的來吧,想學QT
#include <stdio.h> #include <stdlib.h> int main(){ char str[30]={0};//定義一個字符串,其實在C語言中字符串是通過字符數組來進行定義的 scanf("%[A-Z,a-z]",str); char *p=str; while(*p!='\0'){ if(*p>='A'&&*p<='Z') *p+=32; else if(*p>='a'&&*p<='z') *p-=32; p++; } puts(str); return 0; }
發現指針真的很方便,很多用遍歷啊做起來非常麻煩的東西,用指針非常容易解決,就是很多時候你都想不到要去使用指針或者沒有使用指針的意識。就這樣,做程序只能自己慢慢體會,別人沒辦法教你。
