M
Mark
i'm trying to read a file one char at a time into a char[10] array thusly...
char buffer[10];
while (readChars(InputFile, buffer, BUFFER_SIZE) != 0) {
//not doing anything atm
}
int readChars(FILE *InputFile, char buffer[], int readCount)
{
int charsRead = 0;
char ch;
while (((ch=fgetc(InputFile)) != EOF) && (charsRead<readCount)){
//buffer[charsRead] = ch;
//buffer++;
charsRead++;
printf("%d:%c\n", charsRead, ch);
}
return charsRead;
}
readCount is always 10. so say the file contains one line like so...
fdjksfljdsklfdsnm,fndm,
it prints...
1:f
2:d
3:j
4:k
5:s
6:f
7:l
8:j
9:d
10:s
1:l
....
so it's skipping the 11th char, which is k, but i can't figure out what
i'm doing wrong. changing the size of readCount and buffer makes no
difference nor does chaning it to a for loop.
any ideas?
TIA
char buffer[10];
while (readChars(InputFile, buffer, BUFFER_SIZE) != 0) {
//not doing anything atm
}
int readChars(FILE *InputFile, char buffer[], int readCount)
{
int charsRead = 0;
char ch;
while (((ch=fgetc(InputFile)) != EOF) && (charsRead<readCount)){
//buffer[charsRead] = ch;
//buffer++;
charsRead++;
printf("%d:%c\n", charsRead, ch);
}
return charsRead;
}
readCount is always 10. so say the file contains one line like so...
fdjksfljdsklfdsnm,fndm,
it prints...
1:f
2:d
3:j
4:k
5:s
6:f
7:l
8:j
9:d
10:s
1:l
....
so it's skipping the 11th char, which is k, but i can't figure out what
i'm doing wrong. changing the size of readCount and buffer makes no
difference nor does chaning it to a for loop.
any ideas?
TIA