看板 C_and_CPP 關於我們 聯絡資訊
程式碼是這樣 #include<stdio.h> #include<stdlib.h> int main(){ char a,b,m[20]; gets(m); scanf("%c %c",&a,&b); for(int i=0;i<20;i++) { if(m[i]==a){m[i]=b;} } printf("%s",m); system("pause"); return 0; } 相當的簡單 但是我做不出來讀檔txt 因該說 我不會用scanf讀一串文字存在陣列中 scanf讀檔簡單 明天考試 希望解得出來 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.205.125.228 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1450625729.A.131.html
petingo: google c 讀欓 不就一堆了嗎= =? 12/20 23:45
當然拉 找的到一堆 但沒有我要的阿 我要的是用字串 有沒有可已取代gets的東西 不要用cin ※ 編輯: TIANPJ (123.205.125.228), 12/20/2015 23:50:57
grayStone: cin : QQ 12/20 23:53
alex70266: c fileio 12/21 00:04
jaid: 這明明是C.. 12/21 00:10
FILE *f1=fopen("a.txt","r"); fgets(f1,m); fscanf(f1,"%c %c",&a,&b); 這樣不對 9 D:\成檢練習\test11.cpp cannot convert `FILE*' to `char*' for argument `1' to `char* fgets(char*, int, FILE*)' 如何解讀阿 ※ 編輯: TIANPJ (123.205.125.228), 12/21/2015 00:25:08 搞錯用法了 fgets(m,20,f1); 這樣就對了 謝謝大家 特別謝謝alex70226 ※ 編輯: TIANPJ (123.205.125.228), 12/21/2015 00:29:42
overhead: 同學 請至少先google fgets怎麼用 你連引數的數量都錯了 12/21 00:30
overhead: 恭喜 12/21 00:30
Caesar08: 你知道你在寫c code,卻問c++ code嗎? 12/21 09:57
BlazarArc: 這明明是C 12/21 11:35
idiont: 借問一下 用freopen不是比fopen更簡單嗎 12/21 23:05
LPH66: 如果你只讀一個檔而且只讀檔不讀鍵盤輸入那就可以 freopen 12/22 00:28
LPH66: 再說 freopen stdin 其實不是個好做法 12/22 00:29