[問題] C語言xcode檔案輸入輸出
開發平台(Platform): (Ex: Win10, Linux, ...)
xcode8.3.3
問題(Question):
我想要輸入一個txt檔,並列印在螢幕上,可是卻一直跑出null,本人才學C語言幾週,不
知道是錯在哪
801.txt只是一個19位元的亂碼,放在跟程式碼同一個資料夾
#include <stdio.h>
#include <stdlib.h>
int main(int argc, const char * argv[]) {
char txt[1000];
FILE *f1 = fopen("801.txt", "r");
fscanf(f1, "%s", txt);
fclose(f1);
puts(txt);
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.161.11.98
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1501210613.A.2C6.html
→
, , 1F
07/28 11:12
不是,是包含括號、冒號等符號之字串
問題已透過將檔案放置到桌面、更改檔案讀取路徑的方式解決,不過依然想請問各位有沒
有其他辦法?
※ 編輯: egg1127 (1.161.11.98), 07/28/2017 11:16:05
推
07/28 11:19, , 2F
07/28 11:19, 2F
→
07/28 11:34, , 3F
07/28 11:34, 3F
→ Lipraxde: 跟你的801.txt在一起?
是放在一起的,後來把路徑寫詳細後才成功
※ 編輯: egg1127 (1.161.11.98), 07/28/2017 12:22:42
→
07/28 21:55, , 4F
07/28 21:55, 4F
→
07/29 14:48, , 5F
07/29 14:48, 5F
推
08/16 09:14, , 6F
08/16 09:14, 6F
推
08/16 09:16, , 7F
08/16 09:16, 7F