int main(int argc, char* argv[])
{ // this file will be open for appending
FILE *f = fopen("C:\\MyFileName.txt", "ab");
if (!f)
{
printf("Could not open file!\n");
return -1;
}
const char *data = "This is file data";
unsigned int dataSize = strlen(data);
// the write process
if (dataSize != fwrite(data, 1, dataSize, f))
{
printf("Could not write data to file!\n");
fclose(f);
return 666;
}
// if you want to read from a file:
// #define BUFFERSIZE 1024
// char *readData = new char[BUFFERSIZE];
// fread(readData, 1, BUFFERSIZE, f);
// if you know exactly what amount (size) of data should be read
// from the file you could do:
// char *readData = new char[amount];
// if (amount != fread(readData, 1, ammount, f))
// {
// printf("Could not read file data!\n"
// fclose(f);
// return -2;
// }
// this is a "virtual" function that you could call to process
// the data you read from the file
// ProcessData(readData);.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.