Hi all,
I have this code here and I like to save all the messages into 1 text file name contimer.txt. I've tried to do
FILE *output
fopen_s(output,"comtimer.txt", "ww");
right before the function Timer 1 and change every "printf" function into fprint_s(f, "Message", variables) but it does not help. Could I have some pointers? Thank you.
This is my full code
// ConTimer.cpp
// Username: lduong
// Name: Luan Duong
// File: ConTimer.cpp
// Setup and run timers from a Windows Console.
//
#include "stdafx.h"
#define IDT_TIMER1 1
#define IDT_TIMER2 2
#define IDT_TIMER3 3
#define IDT_TIMER4 4
double t1;
int t2;
int t3;
int t4;
double t;
//////////////////////////////////////////////////////////////////////////////////
/// Timer 1
VOID CALLBACK Timer1(HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
{
t = t1/10;
t1++;
printf("At time %f: Timer 1: %f, Timer 2: %d, Timer 3: %d, Timer 4: %d \n",t,t1,t2,t3,t4);
}
//////////////////////////////////////////////////////////////////////////////////
/// Timer 2
VOID CALLBACK Timer2(HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
{
t = t1/10;
t2++;
printf("At time %f: Timer 2 now at %d cycles\n",t,t2);
}
//////////////////////////////////////////////////////////////////////////////////
/// Timer 3
VOID CALLBACK Timer3(HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
{
t = t1/10;
t3++;
printf("At time %f: Timer 3 now at %d cycles\n",t,t3);
}
VOID CALLBACK Timer4(HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
{
t = t1/10;
t4++;
printf("At time %f: Timer 4 now at %d cycles\n",t,t4);
}
//////////////////////////////////////////////////////////////////////////////////
/// Main program
int _tmain(int argc, _TCHAR* argv[])
{
MSG msg; // Windows message structure
HWND hWnd;
UINT_PTR timer_1;
UINT_PTR timer_2;
UINT_PTR timer_3;
UINT_PTR timer_4;
hWnd = NULL;
// Setup the Timers.
if (!(timer_1 = SetTimer(hWnd,
IDT_TIMER1, // Real time data collection timer
1000/10, // 2 Hertz interval
(TIMERPROC) Timer1))) return -1;
if (!(timer_2 = SetTimer(hWnd,
IDT_TIMER2, // Real time data collection timer
1000/5, // 2 second interval
(TIMERPROC) Timer2))) return -2;
if (!(timer_3 = SetTimer(hWnd,
IDT_TIMER3, // Real time data collection timer
1000/2, // 3 second interval
(TIMERPROC) Timer3))) return -3;
if (!(timer_4 = SetTimer(hWnd,
IDT_TIMER4, // Real time data collection timer
1000*2, // 3 second interval
(TIMERPROC) Timer4))) return -4;
t1 = 0;
t2 = 0;
t3 = 0;
t4 = 0;
// Now wait for the timers to timeout.
// In this loop, we ask Windows if it has any
// "messages" for this process.
while (GetMessage(&msg, // message structure
hWnd, // handle to window to receive the message
0, // lowest message to examine
0)) // highest message to examine
{ // A message has been received.
// Dispatche the message.
DispatchMessage(&msg);
if (t>30) break;
}
// Stop the timers.
KillTimer(hWnd, timer_1);
KillTimer(hWnd, timer_2);
KillTimer(hWnd, timer_3);
KillTimer(hWnd, timer_4);
return 0;
}