Hi,
i need to read the system date and time in one file(which is already done).Then in another program i need to read the contents of the first file then check if its has already crossed 1 minute from the current time.i am unable to get how to do it .please help.
Thanks
anuj

ok

#include <stdio.h>
#include <time.h>
#include <string.h>
#define TIME_24   1
#define TIME_12   0

char *get_time_string(int mode24);     /* Returns the time as a string in 12 or 24 hour format */
 main()
{
  char time_str[12];
  get_time_string(TIME_24);

 // printf("\n\n");
  //get_time_string(TIME_12);
}

char* get_time_string(int mode24)
{
  static char time_str[12] = {0};   /* Stroes the time as a string */
  struct tm *now = NULL;
  int hour = 0;
  time_t time_value = 0;
FILE *fp;
fp=fopen("mac.txt","w");

  time_value = time(NULL);          /* Get time value              */
  now = localtime(&time_value);     /* Get time and date structure */
  hour = now->tm_hour;              /* Save the hour value         */
  if(!mode24 && hour>12)            /* Adjust if 12 hour format    */
    hour -= 12;

  fprintf(fp,"%d:",hour);
  fprintf(fp,"%d",now->tm_min);
  //printf("%d",now->tm_sec);

hi,
I tried here in an another way but the diff.txt consists fo some garbage value please suggest me something

#include<stdio.h>
#include<time.h>
main()
{
	time_t rawtime;
	struct tm *timeinfo;
	time(&rawtime);
	timeinfo=localtime(&rawtime);	
	
	int hour2;
	int minute2;
	int seconds2;
	int end1[6];
	int end=0;
	int diff[6];
	int start[6];
	int i=0;
	char ch[6];
	char ch1[6];
	FILE *fp2;
	FILE *fp1;
	FILE *fp4;
	
	
	fp2=fopen("time.txt","r");

	while(!feof(fp2))
	{
		fscanf(fp2,"%c",&ch[i]);
		start[i]=ch[i];
		i++;

	}
	
	
	fp1=fopen("time2.txt","w");
	hour2=timeinfo->tm_hour;
	minute2=timeinfo->tm_min;
	seconds2=timeinfo->tm_sec;
	end=(hour2*3600)+(minute2*60)+seconds2;	
	fprintf(fp1,"%d",end);

	fclose(fp1);

	fp1=fopen("time2.txt","r");

	while(!feof(fp1))
	{
		fscanf(fp1,"%c",&ch1[i]);
		end1[i]=ch1[i];
		i++;
	}
	
	//fp4=fopen("diff.txt","w");
	for(i=0;i<6;i++)
	{
        diff[i]=(end1[i]-start[i]);
	printf("%d",diff[i]);
	i++;
	}
	//fclose(fp1);
	//fclose(fp2);
	//fclose(fp4);

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