View Single Post
Old 04-21-2006, 12:00 AM   #4 (permalink)
jaro
Registered User
 
jaro's Avatar
 
Join Date: Feb 2006
Posts: 9
jaro is on a distinguished road
Hi everyone!
figure out the solution (thanks to some people over the net) . I would like to hear some comment about the solution that I've made.
here's the code: (note this is a test code, to be inserted to a working project)
Code:
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <windows.h>

int x;
char WRITEFILE[50];
char string[200];

int x;
static DWORD	dwDelay = 60000; /* 60000 milliseconds = 60 seconds = 1 minute*/
static DWORD dwTickCount;



int writeToFile(char* str)
{
	FILE* log;

	strcpy(WRITEFILE,"C:\\Dummy.txt");

	log = fopen(WRITEFILE, "a+");
		if (log == NULL)
		{
			return -1;
		}
	fprintf(log, "%s\n",str);
	fclose(log);
	return 0;
}


int main()
{

	
	char timestamp[50];
	time_t t;
	t = time(NULL);

	printf("Start of testProgram.\n");
	writeToFile("Start of testProgram.");
	
	sprintf(timestamp,"%s",ctime(&t));
	timestamp[strlen(timestamp)-1] = '\0';
	writeToFile(timestamp);
	
	dwTickCount = GetTickCount();
	x=0;
	
		while(1)
		{
				if(GetTickCount() - dwTickCount > dwDelay) /* Has 60 seconds elapsed?*/
				{ 
					x++;
					printf("Round %d \n",x);		//print to console 
					sprintf(string,"Round %d",x);	//write to a file
					writeToFile(string);
					dwTickCount = GetTickCount();
				}//end if

		}//end while
	
}//end main
The program will (in every 1 minute) print to console and write to a file a series of increamenting Round.

any comment will be much appreciated.

regards,
jaro
jaro is offline   Reply With Quote