i'm writing a program that write an unsigned char to a file which value is 26 to a file and then reading it and it doesn't work (although it's working with other numbers)
here's the code:
#include <stdio.h>
int main() {
FILE *fp;
unsigned char val1,val2;
val1 = 26;
printf("%d\n",val1);
fp = fopen("test","w");
fwrite(&val1,1,1,fp);
fclose(fp);
fp = fopen("test","r");
fread(&val2,1,1,fp);
fclose(fp);
printf("%d",val2);
getchar();
return 0;
}
that's a rather simple code so i dont know where i made a mistake, do you have any idea why it's not working with 26?
EDIT: with 26 the output is 0
here's the code:
#include <stdio.h>
int main() {
FILE *fp;
unsigned char val1,val2;
val1 = 26;
printf("%d\n",val1);
fp = fopen("test","w");
fwrite(&val1,1,1,fp);
fclose(fp);
fp = fopen("test","r");
fread(&val2,1,1,fp);
fclose(fp);
printf("%d",val2);
getchar();
return 0;
}
that's a rather simple code so i dont know where i made a mistake, do you have any idea why it's not working with 26?
EDIT: with 26 the output is 0