FILE *arquivo = fopen("teste.txt", "rb");
int c;
char a, b[10];
fscanf(arquivo,"%d\n", &c);
printf("%d\n",c);
while ( !feof(arquivo) )
{
fscanf(arquivo,"%c%s\n",&a, b);
printf("%c - %s\n",a,b);
}
}
I works perfectly, but if I change x on "xASDFG" to a white space character like " ASDFG", the white space is not read.
I've tried use this: fscanf(arquivo,"%c%s\n",&a,b); but have same result.
I've tried use this: fscanf(arquivo,"%[^\n]",b); and then split the b string in 2 parts ( first with 1st char and other with rest of the text), but not read white space too.
You have changed the problem from the original problem this is the fixed problem.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
FILE *arquivo = fopen("teste.txt", "rb");
int c;
char a, b[10];
// fscan will on read the information into this and you don't need to worry about the \n's
// except in your printf's
fscanf(arquivo,"%d", &c);
printf("%d\n",c);
for(int count = 0; count < c; count++)
{
fscanf(arquivo,"%s", b);
printf("%c\t",b[0]);
printf("%s\n", *b[1]);
}
I apologize for my flub its been a while since I did strait c to get things done. I do heavy c-string manipulations in a lot of things of old code but I convert to a pointer do pointer math. A lot of the c++ programmers out here didn't program before 98.
I do agree with cire that the file doesn't need to be opened as binary. Your reads would match the form of the open. In other words, you wouldn't be using fscan and you would be using exclusively freads and expecting to get everything plus the end of line characters. It would also require a little stronger thought of file pointer manipulation.