Reading numbers from a text file into an array in C - Stack Overflow

PHOTO EMBED

Sun Mar 27 2022 23:37:02 GMT+0000 (Coordinated Universal Time)

Saved by @danihf23 #c

#include <stdio.h>
#include <stdlib.h>

int main(){

    FILE *myFile;
    myFile = fopen("somenumbers.txt", "r");

    //read file into array
    int numberArray[16];
    int i;

    if (myFile == NULL){
        printf("Error Reading File\n");
        exit (0);
    }

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

    for (i = 0; i < 16; i++){
        printf("Number is: %d\n\n", numberArray[i]);
    }

    fclose(myFile);

    return 0;
}
content_copyCOPY

https://stackoverflow.com/questions/20378430/reading-numbers-from-a-text-file-into-an-array-in-c