題目:從鍵盤輸入一個字符串,將小寫字母所有轉換成大寫字母,而後輸出到一個磁盤文件"test"中保存。 輸入的字符串以!結束。html
程序分析:無。學習
程序源代碼:spa
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 5 int main() 6 { 7 FILE*fp=NULL; 8 char str[50]; 9 int i,len; 10 printf("輸入一個字符串:\n"); 11 gets(str); 12 len=strlen(str); 13 for(i=0;i<len;i++) 14 { 15 if(str[i]<='z'&&str[i]>='a') 16 str[i]-=32; 17 } 18 if((fp=fopen("test","w"))==NULL) 19 { 20 printf("error: cannot open file!\n"); 21 exit(0); 22 } 23 fprintf(fp,"%s",str); 24 fclose(fp); 25 26 system("pause"); 27 return 0; 28 }
以上實例運行輸出結果爲:code
輸入一個字符串:
www.kangyifan.com
感謝你的閱讀,請用心感悟!但願能夠幫到愛學習的你!!分享也是一種快樂!!!請接力。。。htm
點擊查看原文,謝謝!blog