[問題] c++ txt讀檔
程式碼是這樣
#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
推
12/20 23:45, , 1F
12/20 23:45, 1F
當然拉 找的到一堆 但沒有我要的阿 我要的是用字串 有沒有可已取代gets的東西
不要用cin
※ 編輯: TIANPJ (123.205.125.228), 12/20/2015 23:50:57
→
12/20 23:53, , 2F
12/20 23:53, 2F
→
12/21 00:04, , 3F
12/21 00:04, 3F
→
12/21 00:10, , 4F
12/21 00:10, 4F
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
→
12/21 00:30, , 5F
12/21 00:30, 5F
→
12/21 00:30, , 6F
12/21 00:30, 6F
→
12/21 09:57, , 7F
12/21 09:57, 7F
→
12/21 11:35, , 8F
12/21 11:35, 8F
推
12/21 23:05, , 9F
12/21 23:05, 9F
推
12/22 00:28, , 10F
12/22 00:28, 10F
→
12/22 00:29, , 11F
12/22 00:29, 11F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章