我正在編寫代碼,我需要使用循環。我正在從一個文件(data.txt)讀取數據,如下所示:循環無法識別C中的字符串
IMPORT 450
EXPORT 200
IMPORT 100
等等。
這裏是我有
inputfile = fopen("c:\\class\\data.txt","r");
fscanf(inputfile,"%s %f", &transaction, &amount);
do{
total += amount;
printf("Data %s %f %f\n", transaction, amount, total);
fscanf(inputfile, "%s", &transaction);
}while (transaction == "IMPORT" || transaction == "EXPORT");
麻煩當我添加一個printf線檢查什麼「交易」,因爲它顯示導入代碼段,所以我不知道爲什麼做 - while循環不重複。
謝謝!