Exactly what the sibject says. I'm getting nothing in blah.log.Code:FILE * Log; fopen("blah.log", "a"); fprintf(Log, "blah.log", "Test"); fclose(Log);
BTW, I need to use append mode......
Exactly what the sibject says. I'm getting nothing in blah.log.Code:FILE * Log; fopen("blah.log", "a"); fprintf(Log, "blah.log", "Test"); fclose(Log);
BTW, I need to use append mode......
The world is waiting. I must leave you now.
> fprintf(Log, "blah.log", "Test");
You shouldn't have the second , in there.
fprintf( Log, "blah.logTest" );
Or
fprintf( Log, "blah.log" "Test" );
Quzah.
Hope is the first step on the road to disappointment.
well i'll assume your code was just ment as an example and not actually what you are running.
quzah,Code:#include <stdio.h> int main(void) { FILE * Log; // you must open the file path correctly(eg."C:\\mypath\\path\\file.bla") // Note: the double backslash '\\' Log = fopen("C:\\blah.log", "a"); fprintf(Log, "blah.log%s", "Test"); fclose(Log); return 0; }
that infact should cause no problem the "blah.log" should be written and the "Test" should be ignored.
Last edited by no-one; 02-13-2002 at 03:45 PM.
ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.
Quzah,
You took me back to square one lol. Thanks for the effort.
no-one,
I have a file pointer with Log.Code:int main() { FILE * Log; Log = fopen("blah.log", "a"); fprintf(Log, "Test"); fclose(Log); return 0; }
*NEW* I'm _using_ the file pointer Log to open a file called "blah.log" ( or to create one if none exist ).
I'm using the file pointer log to -direct- the printing instructions to the "currently" associated file, blah.log
I then close the file pointer Log.
I'd then be able to assign the file pointer Log to a different text file if I wished........
I had the file pointer log setup, but wasn't using it!
The world is waiting. I must leave you now.
so the problem is solved?
it took me a minute to see that Log was not being assigned also.
ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.
It's solved, and now with Cprogramming.com's tutorials, I am refreshing a little bit of my "time" command skills....
This all works perfectly, just how I want it. The program opens and immediately upon opening it opens that log file & logs the time this program was activated so-to-speak. I put a getch(); command in there just to pause the program so that a few seconds will pass by. This way when the time of closing was logged, and the clock is updated, we will visually see the time this program was running inside that log file.Code:int main() { // Setup clock / timer // Setup log file time_t hold_time; hold_time=time(NULL); FILE * Log; // Open log file // Write the date & time into the log file along with "Menu opened" // to -log- the time that menu was first opened. Log = fopen("Menu.log", "a"); fprintf(Log, "%s", ctime(&hold_time)); fprintf(Log, "Menu opened\n\n"); // Pause the program flow to allow a few seconds to go by getch(); // "Refresh" the timer so when "Menu closed" was logged // it will also have the updated time. hold_time=time(NULL); fprintf(Log, "%s", ctime(&hold_time)); fprintf(Log, "Menu closed"); fclose(Log); return 0; }
Is there a way to convert military time to standard time?
00:01:05 = 1:05am?
The world is waiting. I must leave you now.
heres a stripped down example from the MSDN
Code:#include <time.h> #include <stdio.h> #include <sys/types.h> #include <sys/timeb.h> #include <string.h> void main() { char ampm[] = "AM"; time_t ltime; struct tm *today, *gmt; gmt = gmtime( <ime ); /* Convert to time structure and adjust for PM if necessary. */ today = localtime( <ime ); if( today->tm_hour > 12 ) { strcpy( ampm, "PM" ); today->tm_hour -= 12; } if( today->tm_hour == 0 ) /* Adjust if midnight hour. */ today->tm_hour = 12; /* Note how pointer addition is used to skip the first 11 * characters and printf is used to trim off terminating * characters. */ printf( "12-hour time:\t\t\t\t%.8s %s\n", asctime( today ) + 11, ampm ); }
ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.