You are here

one minute executable

//This program works for 1 minute and then prompt the user to enter the key.

#include<time.h>
#include<dos.h>
#include<stdio.h>
#include<conio.h>

int main()
{
struct date d;
struct time t1;
char str[20], get[20], key[]="123456", ch;
int a, b, c;
long time1, time2;
FILE *fp;
int valid = 0, htime = 0;

clrscr();

fp = fopen("C:\Docume~1\administrator\applic~1\logtime.txt","a+");
if(fp == NULL)
{
printf("Cannot open file. Press any key to exit...");
perror("Error: ");
getch();
exit(0);
}
else
{
getdate(&d);
gettime(&t1);
time2 = dostounix(&d,&t1);
ltoa(time2,str,10);
fseek(fp,2,SEEK_SET);
fscanf(fp,"%d",&htime);
if( htime == 0 )
{
htime = 1;
fprintf(fp,"%d %d %ld",valid,htime,time2);
time1 = time2;
}
else
{
fseek(fp,0,SEEK_SET);
fscanf(fp,"%d",&valid);
fseek(fp,4,SEEK_SET);
fscanf(fp,"%ld",&time1);
}

}
if( time2 - time1 >= 60 && valid == 0 )
{
gotoxy(28,1);
printf("Trial version has expired.\n");
gotoxy(32,3);
printf("Please Register");
gotoxy(25,5);
printf("Programming Simplified\n\n");

printf("Do you have the key (y/n) ");
fflush(stdin);
scanf("%c",&ch);
if(ch == 'y' || ch =='Y')
{
printf("\nEnter the key\n");
fflush(stdin);
gets(get);
if( strcmp(get,key) == 0 )
{
printf("Congratulations! Registration is complete now.");
printf("\nPress any key to continue...");
getch();
clrscr();
valid = 1;
fseek(fp,0,SEEK_SET);
fclose(fp);
fp = fopen("logtime.txt","r+");
fprintf(fp,"%d",valid);
}
else
{
printf("\nInvalid Key. Press any key to exit...");
getch();
exit(1);
}
}
else
{
exit(0);
}
}
fclose(fp);
if ( valid == 0 )
{
gotoxy(34,1);
printf("Trial Version");
gotoxy(1,3);
printf("This program works for 1 minute only and then prompts the user to enter the key.");
gotoxy(11,5);
printf("Please execute it also after a minute and see what happens.");
gotoxy(25,7);
printf("Programming Simplified\n");
}
else
{
gotoxy(21,1);
printf("This program has been registered now.");
gotoxy(25,3);
printf("Programming Simplified\n");
}
printf("\nEnter two integers to calculate their sum : ");
fflush(stdin);
scanf("%d%d",&a,&b);
c = a+b;
printf("Sum of entered integers = %d",c);

getch();
return 0;
}