I made a program in C, the output it provides is correct, however the output format(which is specific) is incorrect. I will not post the entire program because it is unnecessary however I will post a smaller, to-the-point program that I made for the purposes of solving this minor headache:-
Code:
#include <stdio.h>
#include <string.h>
int main(){
char testarray[10][17];
int somenumber=7484,count;
FILE *in;
in = fopen("test.in","r");
for(count=1;count<=5;count++){
fgets(testarray[count],sizeof testarray,in);
}
for(count=1;count<=5;count++){
printf("%s %d",testarray[count],somenumber);
}
}
The file has some text line-by-line. The output format that should have been there(and is there in code without the two-dimensional array, however the output is incorrect):-
Code:
text number
text number
The resultant output format from the above code is:-
Code:
text
number
text
number
which leads me to believe that something in the array is incorrect, probably due to fgets since it seems to work fine with fscanf, but I can't put my finger as to what the exact problem is or how to solve it.
Thanks in advance for any help in this problem.
Bookmarks