開發平台(Platform): (Ex: Win10, Linux, ...)
Win10
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
code: blocks
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
在練習檔案的讀寫時 讀取檔案讀不到下一行
餵入的資料(Input):
無
預期的正確結果(Expected Output):
fscanf = 1
line = 26.000000,-74.000000,James
fscanf = 1
line = 26.500000,-73.000000,James
fscanf = 1
line = 27.000000,-72.000000,James
fscanf = 1
line = 27.500000,-71.000000,James
fscanf = 1
line = 28.000000,-70.000000,James
錯誤結果(Wrong Output):
fscanf = 1
line = 26.000000,-74.000000,James
fscanf = 0
line = 26.000000,-74.000000,James
fscanf = 0
line = 26.000000,-74.000000,James
fscanf = 0
line = 26.000000,-74.000000,James
fscanf = 0
line = 26.000000,-74.000000,James
程式碼(Code):(請善用置底文網頁, 記得排版,禁止使用圖檔)
http://codepad.org/f2JGKJsS
補充說明(Supplement):
無
作者:
ddavid (謊言接線生)
2021-01-18 11:10:00雖然寫起來可能比較反而複雜,但我比較喜歡fgets一行進來後再對那行字串做處理的方式,只要寫成function模組化其實用起來還是方便且出錯容易知道問題例如將原本的code改成先 str_line = fgets(...);然後才用sscanf(str_line, "...", ...);不過fgets讀取有上限長度,這方面還要確認一下使用例會不會容易莫名其妙發生過長列需要額外處理