-
File reading and arrays
I have this program and it suppose to read a file for an 52 char string. Then process the string. The y and n are use to process diffrent things I can't even get it read form the file right. It goes through the loop 12 time to get 5 lines of data. Is there easerway to get the info aout of the file then i'm using?
Latter on i need you use the n and y, but when i print the array out it does everthing 2 times( prints it twice, instead of 5 lines i get 10 lines of the same code) like there extra code when i put a for loop to print the first 31 char out.
here the file
YNYNYNYNYNYNYNYNYNYNYNYNYNYN1302 Coleridge Avenue
NYNYNYNYNYNYNYNYNYNYNYNYNYNYNY2311 Avenue A West
YYYYYNNNNNYYYYYNNNNNYYYYYNNNNN10656 Rondo Avenue
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNN111 N. Montgomery Rd.
NNNNNYYYYYNNNNNYYYYYNNNNNYYYYYNE 53rd Street
here the code
#include <stdio.h>
int main()
{
char Apart[52] , i ;
FILE *input_file ;
int counter = 1, n = 1 ;
/* If no file the give error */
if ( ( input_file = fopen( "i:\\c\\files\\Apts.dat", "r" ) ) == NULL )
fprintf(stderr,"The input file could not be opened.\n");
else
while(!feof(input_file))
{
n++;
fgets(Apart, 52, input_file);
printf("%s", Apart);
}
printf("%d", n);
fclose (input_file); /* Close file */
return ;
}
-
try opening the file in "rb" mode(as it's a binary file....I suppose)
-
Thanks you very much, that works.