Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
how to connent to the logfile with c project in pc?
Posted
Comments
enhzflep 28-Nov-11 22:31pm    
FILE *logFile;
char *logFileName = "logfile.log";
char *accessPermissions = "a+";
logFile = fopen(logFileName, acessPermissions);
[no name] 28-Nov-11 22:34pm    
Please clarify your question. We could not understand.
Albert Holguin 28-Nov-11 22:56pm    
If you haven't caught on... No such thing as "the logfile", although you can make a file and call it a log file (or whatever you want).

1 solution

C#
#define MAX 50;
FILE *logFile;
char logFileName[MAX] = "logfile.log";
char accessPermissions[MAX] = "a+";
logFile = fopen(logFileName, acessPermissions);

Use
C++
fwrite(); 
method to write to the file
 
Share this answer
 
v2
Comments
enhzflep 28-Nov-11 22:57pm    
Gawd almighty! Why would one write to a text file using fwrite? That's unpleasant on a good day for text stuffs.

Simply use fprintf and be done with it - unless of course, you also use fwrite to put text on the screen via the stdout file handle!
Sergey Alexandrovich Kryukov 28-Nov-11 23:09pm    
You are right :-)
--SA
Selva K 28-Nov-11 23:19pm    
why we should not use fwrite(), what is the difference ?
sorry for using that.
enhzflep 28-Nov-11 23:53pm    
While it's perfectly legal to use fwrite, it's rather inconvenient and doesn't do any text formatting for you. To do that, you'd have to use sprintf to put it into a string before then using fwrite to write that string. MUCH easier to simply use fprintf.

E.g -
FILE *fp;
char *fileName = "logFile.log";
char permissions = "a+";
int i;

fp = fopen(fileName, permissions);


// method 1 - using fprintf
for (i=0; i<10; i++)
fprintf(fp, "This is line %d\n", i);


// method 2 - using fwrite
char lineBuffer[256]; // hope it's large enough!
for (i=0; i<10; i++)
{
sprintf(lineBuffer, "This is line %d\n", i);
fwrite(lineBuffer, 1, strlen(lineBuffer), fp);
}
Selva K 29-Nov-11 1:29am    
Thank you...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900