Hey there guys.
Don't worry, i won't ask you for making my homework, lol..
My question is simple. I want to read a file, with integers inside, and pass those values to an array of int's.
The question is, the program has to work with an undefined number of values, like, i can't initialize an array like this: int array[10].
I'm going to put my code here so you can understand:
Question 1: is the syntax "int array[];" correct? it has a undefined size, right?Code:void main(){ int line_temp; int aux; int c; int number; FILE * fp; int array[]; char name[20]; printf("File name:\n"); scanf("%s",name); fp = fopen(name,"r"); c = getc(fp); while (c != EOF){ fscanf(fp,"%s",linha_temp); sscanf(linha_temp,"%d",&number); } }
Question 2: how do i avoid creating N int's for the storage of the file numbers? (if there are 500 numbers, i guess it's stupid to initialize 500 ints)
I guess this is only saving the first number on the file..
I need some help please, i appreciate it in advance
Thank you, peace



LinkBack URL
About LinkBacks




