DIGITAL CLOCK
In this blog I will be providing you with the code of making a simple clock using C Language.I hope that you will like it.
CODE:-
#include<stdio.h>
#include<stdlib.h>
void print1(char *x[20]){ //This is the function for printing the output i.e. a day ahead.
char *day[20]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
//above array is created to store the days.
char *res[1];// this array is created to store the result.
int i,flag,result;
for(i=0;i<7;i++){
result=strcmp(x,day[i]);//This is used to compare two strings.If the two strings are same,then it will return a value0.*
if(result==0){ //* and if not then ,it will return a non zero number.
*res=*(day+i+1);
flag=1;
}
}
if(flag==1){
printf("%s",*res);
}
}
void print2(char*x[20]){//This is the function for printing the output i.e. today.
char*day[20]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
char *res[20];
int i,flag,result;
for(i=0;i<7;i++){
result=strcmp(x,day[i]);
if(result==0){
*res=*(day+i);
flag=1;
}
}
if(flag==1){
printf("%s",*res);
}
}
int main(){
char *user[20];
//system("cls");
int h,m,s,flag=0;
double i;
printf("Enter the time in hours : ");
scanf("%d",&h);
printf("Enter the time in minutes: ");
scanf("%d",&m);
printf("Enter the time in seconds: ");
scanf("%d",&s);
printf("Enter the day: ");
scanf("%s",&user);
if(h<12){
flag=1;
}
start:
for(h;h<24;h++) {
for(m;m<60;m++) {
for(s;s<60;s++) {
system("cls");//This command is for clearing the previous inputs and outputs on the screen.
system("color 4");//This is for the text color.this is completely optional
printf("\n\n\n\t\t\t%d:%d:%d",h,m,s);
if(h<12){
if(flag==1){
printf("\n\n\t\t\tA.M.\t");
print2(user);//It will print the same day.
}
else{
printf("\n\n\t\t\tA.M.\t");
print1(user);// It will print the next day.
}
}
else
{
system("color 4");
printf("\n\n\t\t\tP.M.\t");
print2(user);
}
for( i=0;i<126299995;i++) {
}
}
s=0;// whenever the second loop ends,the value of second will become 0 and after that seconds will be counted from 0.
}
m=0;// whenever the minute loop ends,the value of minute will become 0 and after that minutes will be counted from 0.
}
h=0;// whenever the hour loop ends,the value of hour will become 0 and after that hours will be counted from 0.
goto start;// this is done, so that the clock won't stop.Otherwise the clock will stop at 23:59:59.
getch();
return 0;
}
Comments
Post a Comment