folks, this is an example I took from the Internet, I modified it a bit, the 'wb' to 'w', and 'bin' to 'txt' for the sake of understanding it.
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE * fp;
int x = 0, i = 0;
fp = fopen ("TestFile.txt", "w");
for(i=0; i<10 ;i++) {
x = i;
fwrite(&x,sizeof(int),1,fp);
};
fclose(fp);
return(0);
}
What is really happening here? 1 The 'w' mean that I want to write in a textfile. 2 What is stored inside is in binary format. Question 1&2: The extension doesn't mean anything here, is the 'w' that defines that it is a textfile, even with inside data in binary?
3 The fact that I'm trying to store a 4 bytes inside a file that accepts 1 byte transform it in binary?
I know that I can create plain text this way.
char y = i + '0';
fwrite(&y,sizeof(char),1,fp);
4 Anyone actually stores numbers in plain text? How, what's the best way to do that? Thanks in advance.