I have two integer variables at rp
and rc
, and I have to write them to a file as a way to save their value, and then get them and put them into variables of type inteiro
to use in my program.
To write to a file, I'm just using an escape character to let me know if the number is gone or not. This character is the semicolon ;
.
I'm trying with the following code, where arq
is my file:
To get value:
cc = 1;
while(! feof(arq))
{
get = fgetc(arq);
if(get != ';')
{
if(cc == 1)
{
rc = (int)get;
cc ++;
}
else
rp = (int)get;
}
}
fclose(arq);
To place:
fputc(rc, arq);
fputc(';', arq);
fputc(rp, arq);
fputc(';', arq);
I know where the error is, but I do not know how to fix it. It is taking the value ASCII
of the character - when I put an integer it takes the value ASCII
and not the number, and when it happens the same happens, it converts the integer to char
and uses ASCII
.
Another problem is that I'm only taking one-digit numbers into account; how do I take larger numbers into account?