簡體   English   中英

將數字從文件掃描到數組

[英]Scanning numbers from file into array

下面列出的文件中包含將這些數字插入兩個單獨的數組的代碼:

18 18 25 31 37 82 82 87 89 230 85 87 558

3 3 3 3 3 3 5 4 4 4 10 3 3 10

工作和輸出都不是巨大的,例如2686616 2686632 4 1991898240 0 10027008 -352000039 0 2686632 1991898249 1991898624

任何人都可以幫助解決此問題? 抱歉,這只是在main內部,它具有合適的include和main {}

FILE *locFile;
LOCFile = fopen("c:\\locvalues.txt", "r");
FILE *methodFile;
methodFile = fopen("c:\\methodvalues.txt", "r");


int locArray[13];
int methodArray[13];
int i;

for (i = 0; i < 13; i++)
{
    fscanf(locFile, "%d", &locArray[i]);
    fscanf(methodFile, "%d", &methodArray[i]);

}

for (i = 0; i < 13; i++)
{
    printf("%d\n", locArray[i]);
    printf("%d\n", methodArray[i]);
}

fclose(locFile);
fclose(methodFile);

如注釋中所示,如果在第二行用locFile替換LOCFile並重新編譯,則示例代碼應運行良好。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM