1
我想知道如何從文本文件中讀取數據,其數據用逗號分隔;例如文本文件的第1行說: (名稱,整數,整數)。如何讀取以','分隔的文本文件中的數據C
於是,我就用這個代碼讀取的代碼,但它不工作:
while (fscanf(ifp, "%15s,%d,%d", stationName, &stationDistance, &stationDirection) == 2) {
strcpy(q[fileCounter].name, stationName);
q[fileCounter].distance = stationDistance;
q[fileCounter].direction = stationDirection;
printf ("Station Name: %s \t Distance to Central: %d \t Direction from Central: %d \n", q[fileCounter].name, q[fileCounter].distance, q[fileCounter].direction);
fileCounter++;
}
你是否教過我這麼多,我完全不知道你可以做任何事情,非常感謝你,但是由於某種原因,現在它沒有進入循環? – MattSolo
我將需要你從輸入文件中發佈數據。 –
數據如下:「Taren Point,10,S」 - >下一行「Ashfield,6,W」 – MattSolo