[問題] C語言讀檔

看板C_and_CPP (C/C++)作者 (President)時間15年前 (2011/04/02 20:44), 編輯推噓0(003)
留言3則, 2人參與, 最新討論串2/2 (看更多)
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) #include<stdio.h> #include<stdlib.h> void toUpper(char s[]); int main(void) { char str[100]; printf("請輸入字串:"); gets(str); toUpper(str); printf("轉成大寫之後:%s\n",str); return 0; } void toUpper(char s[]) { int i=0; while(s[i]!='\0') { if(s[i]>=97 && s[i]<=122) s[i]=s[i]-32; i++; } } 請輸入字串:Happy Birthday 轉成大寫之後:HAPPY BIRTHDAY 請問這種鍵盤輸入要怎麼改成讀檔的方式然後轉換大寫? 例如從a.txt讀入Happy Birthday然後轉成HAPPY BIRTHDAY 懇請大家麻煩解決!!!謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 125.231.219.36

04/02 20:49, , 1F
你可以搜尋fopen, fgets, fclose這幾個函式的用法
04/02 20:49, 1F

04/02 23:55, , 2F
freopen("filename" , "r"or"w"or"a"... , stdin )
04/02 23:55, 2F

04/03 00:17, , 3F
如果要換大寫請參考ctype.h
04/03 00:17, 3F
文章代碼(AID): #1DbneT66 (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #1DbneT66 (C_and_CPP)