Hello! i am a beginner and want to file handling concept in win32 application for writing anything say text in file which is present in some location on hard disk.
Please Reply
Thanks in advance...
Hello! i am a beginner and want to file handling concept in win32 application for writing anything say text in file which is present in some location on hard disk.
Please Reply
Thanks in advance...
You can do in this way Suppose there is a folder called "XYZ" at "E:" drive & the file name is "abc.log" and the function which u call is say "WSL".
VOID __cdecl WSL(char *message);//function declaration
//Function definition:
VOID __cdecl WSL(char *message)
{
static int lineNo = 1;
FILE *fp = fopen("E:\\XYZ\\abc.log","a+");
if(fp!= NULL)
{
fprintf(fp,"%d : %s\n",lineNo++,message);
fclose(fp);
}
}
and at main function u r coding the following:
int main()
{
FILE *fp = fopen("E:\\XYZ\\abc.log","w");
WSL("Application opened");
........
........
........
........
........
WSL("Application closed");
}
This will write two time at abc.log file since it is called twice in your main function.
First time it will print...
1. Application opened
& second time it will print
2. Application closed
Use fstream to write to a file, rather than win32 API. This is for RAII reasons, and it is also more standard.
There are several ways to do that. 1. Use functions fopen(), fwrite(), fclose() 2. Use std::fstream