如何避免閱讀分號;在FILE中並將它們保存在變量中?如何忽略';'在fscanf文件中?
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void)
{
char gstitem[6], gstname[30],;
int gstquant, itemquant;
float gstprice;
char string[10];
printf("Purchase items fuction\n\n");
FILE *gstPtr; //pointer to the gst.txt
gstPtr = fopen ("gst.txt", "r+");
printf("Enter an item code: ");
fgets(string,10,stdin);
(!feof(gstPtr));
{
fscanf(gstPtr,"%[^;]s %[^;]s %[^;]f %[^;]d\n",gstitem,gstname,&gstprice,&gstquant);
printf("%s %s %f %s\n",gstitem,gstname,gstprice,gstquant);
}
fclose(gstPtr);
}
這是我想FSCANF VV
您的圖片文字少量:請張貼文字作爲問題的一部分。 [Minimal,Complete,and Verifiable example](http://stackoverflow.com/help/mcve)的思想是讓讀者可以複製和嘗試代碼及其輸入數據。 –
不檢查'fscanf()'的結果是[_Road to Perdition_](http://www.dictionary.com/browse/perdition), – chux
循環之前'fgets'的目的是什麼?什麼是循環控制'(!feof(gstPtr));'[原文如此]?除了謹慎使用[feof'](http://stackoverflow.com/questions/5431941/why-is-while-feof-file-always-wrong)之外,控制循環的方法是返回(fscanf(...)== 4){...}' –