Reading numbers from a text file into an array in C

后端 未结 5 706
囚心锁ツ
囚心锁ツ 2020-11-30 05:00

I\'m a programming noob so please bear with me.

I\'m trying to read numbers from a text file into an array. The text file, \"somenumbers.txt\" simply holds 16 number

5条回答
  •  無奈伤痛
    2020-11-30 05:23

    for (i = 0; i < 16; i++)
    {
        fscanf(myFile, "%d", &numberArray[i]);
    }
    

    This is attempting to read the whole string, "5623125698541159" into &numArray[0]. You need spaces between the numbers:

    5 6 2 3 ...
    

提交回复
热议问题