Reputation: 23
I've been struggling for more than a day trying to figure out what's wrong with this piece of code,printf is always printing 0 on my screen.
#include <stdio.h>
#include <ctype.h>
int main()
{
int one=0,two=0;
FILE *arq;
arq = fopen ("testando.txt","w+");
fprintf(arq,"1,2,3\n");
fscanf(arq,"%d%d",&one,&two);
printf("%d %d\n",one,two);
return 0;
}
Upvotes: 1
Views: 113
Reputation: 172
fscanf(arq,"%d%d",&one,&two);
r
flag - to read itThis works fine:
#include <stdio.h>
#include <ctype.h>
int main()
{
int one=0,two=0;
FILE *arq;
arq = fopen ("testando.txt","w+");
fprintf(arq,"1,2,3\n");
fclose(arq);
arq = fopen("testando.txt","r");
int r = fscanf(arq,"%d,%d",&one,&two);
fclose(arq);
printf("%d %d %d\n",r, one,two);
return 0;
}
Output:
2 1 2
Upvotes: 2