I am trying to Ccate a program that will read from a file, a list of
any sort(numbers, strings, names, etc. ) store them into an array and print them out in reverse order into an output file. Could someone please get me started?
Printable View
I am trying to Ccate a program that will read from a file, a list of
any sort(numbers, strings, names, etc. ) store them into an array and print them out in reverse order into an output file. Could someone please get me started?
1) Look in the FAQ for file I/O
2) Look up sorting routines
3) The rest is easy
4) Gratz on being the 300th member!
I didn't test this but it should be right or else close to perfect or whatever the hell...Code://open the file
FILE *fptr = fopen(filename,"r"); if(fptr == NULL) exit(1);
//read input
int i_array[20];
int i=0;
while(fscanf(fptr,"%d",&i_array[i]) != NULL)
{
++i;
if(i >= 20) break;
}
--i;
while(i > 0)
{
printf("%d\n", i_array[--i]);
}