hi all, i'm working on a c program that would sort an array of numbers, and then compare with another text file produced by a sorting program to see if they match.
Before I dealt with numbers that are in one column, so I just used the code below and it did the job of getting the numbers into an array.
Code:
while ( !feof(streamSorted ) )
{
fscanf_s( streamSorted, "%d", &sorted[sortedSize] );
sortedSize++;
}
Now I have to deal with numbers that has formatting. There are now two columns of numbers instead of just one. First column is random numbers, unsorted, and * marks the end of each group. 2nd column is sorted, and # marks the end of the group. Either column one or two could be empty. For example,
2
3
1
5
4*
1
9 2
8 3
10 4
12 5#
11
6
7* 6
13 7
15 8
...
I will need to load all of the unsorted groups into an array, and the sorted groups into another one.
Someone suggested to use fgets() but I don’t exactly see how it can do the job?
Can someone please point it out? Thanks so much…