0
我正在嘗試讀取 - 寫入一個txt文件,該文件在不同的行中包含多個信息。 它是形式:讀寫C文件中的文本文件
Number-LicencePlate NumberOfSeats
Name number phonenumber
Name number phonenumber
Name number phonenumber
要閱讀的第一行是很容易使用的fscanf 但是,如何才能使用的fscanf獲得3個不同的變量,我讀它的其餘部分(姓名,號碼,電話) ?
寫入該文件在相同的形式是在一個稍後的階段,但會盡力去解決它..
FILE *bus;
bus = fopen ("bus.txt","r");
if (bus == NULL)
{
printf("Error Opening File, check if file bus.txt is present");
exit(1);
}
fscanf(bus,"%s %d",platenr, &numberofseats);
printf("Bus Licence plate Nr is: %s and number of seats is: %d", platenr, numberofseats);
噸:https://www.google.com/search?q=how+to+read+text+file+using+fscanf+site%3Astackoverflow.com – alk
使用while循環! –
可能重複[在C中,我應該如何讀取文本文件並打印所有字符串](http://stackoverflow.com/questions/3463426/in-c-how-should-i-read-a-text-file - 和 - 打印所有字符串) –