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;
}

I will gladly be more specific; allow me to take this opportunity to remind ye' that YOU ARE POSTING C CODE IN A C++ FORUM. I don't go to a Java forum and post Pascal. I don't go to a C# forum and post QBasic. I don't go to McDonalds and ask for a Whopper. Why do people insist on posting C code up in here and expect results...???!

Comments
Cool it. It's not the end of the world.

I will gladly be more specific; allow me to take this opportunity to remind ye' that YOU ARE POSTING C CODE IN A C++ FORUM. I don't go to a Java forum and post Pascal. I don't go to a C# forum and post QBasic. I don't go to McDonalds and ask for a Whopper. Why do people insist on posting C code up in here and expect results...???!

C is C++. When an instructor in the C++ course starts with the easier (to them) syntax of C, they teach C under the guise of C++. The student doesn't know any better so they post here. This is perfectly acceptable so stop getting you knickers in a snit. It's not worth it.

Comments
you said 'knickers' and 'wad' in the same sentence.

Dear Clinton Portis,
I'm sorry if I bothered you with my codes, but I don't know and I've never learn C code. This is a C++ class and I'm doing my project in C++ of visual studio.
If in fact my code is C (if my instructor lied to me) then you should point it out instead of insulting people like that.

This article has been dead for over six months. Start a new discussion instead.