HI i'm new to C programming and i wanted to ask where the error is in that part of code it is supposed to open a .txt file placed in the same folder and print the numbers that it contains onto the screen but i'm reciving a segmentation fault; I'm using the Xcode compiler that's embedded in an apple developers pack...
that's the code...
Code:#include <stdio.h> #include <stdlib.h> int main() { FILE *file; int numbers[3000]; int i,j; file = calloc(3000, 10); file = fopen("numeri.dat", "r+"); printf("File opened successfully.\n"); i = 0 ; while(!feof(file)) { fscanf(file, "%d", &numbers[i]); i++; } printf("The numbers are:\n"); for(j=0 ; j<i ; j++) { printf("%d\n", numbers[j]); } fclose(file); free(file); return 0; }



LinkBack URL
About LinkBacks


