Inputting the Date using C
Learn how to take Correct Date in Inputting the date using C and Printing in a suitable form. Learn through an Example
C program to display date using the structure
#include <stdio.h>
#include <stdio.h>
//#include <stdbool.h>
//#include<string.h>
//#include<ctype.h>
int chk_date(char []);
int count=0;
int main()
{
int z=-1;
char s[11];
do{printf(“\nEnter date in format dd/mm/yyyy : “);
gets(s);
printf(“\nEntered date is = %s”,s);z=chk_date(s);
if(z==0)
printf(“\nInvalid date“);
}
while(z!=1);printf(“\nValid date“);
return 0;
}int chk_date(char x[])
{
int i=0;
char d[3];
char m[3];
char y[5];int day;
int month;
int year;while(x[i]!=’\0′){
if(!isdigit(x[i]) && x[i]!=’/’)
{
return 0;
}
else
{
if(x[i]==’/’)
{
if(i==2)
{
d[0]=x[0];
d[1]=x[1];
}if(i==5)
{
m[0]=x[3];
m[1]=x[4];
}}
else
{
y[0]=x[6];
y[1]=x[7];
y[2]=x[8];
y[3]=x[9];
}
}i++;
}day=atoi(d);
month=atoi(m);
year=atoi(y);if(day<=0 || day>31)
return 0;
if(month<=0 || month >12)
return 0;
if(year<1000 && year >9999)
return 0;if(x[2]!=’/’ && x[5]!=’/’)
return 0;
return 1;
}
C Program to print the date in legal form
In this program when you entered the date in the wrong form:- Ex. Palace of Month (1-12), But you entered the palace of Month like 13th or Greater than. Then this program will show you a Message like Invalid Input.
C program to store date in an integer variable
When you entered the Correct input then the message will be shown to you in the following Image.
C program to draw a square using graphics (clickHere)
Note:- Maybe sometime above code doesn’t get user-friendly output, in codeblock ‘or’ any other EDITOR, All of C & C++ program tested in DOS compiler Turbo C.
Also Read
Types of functions in C Read Here
I hope you will understand better if you study at M.U, in the exam of M.U you know how important this “Inputting the date using C. So please don’t forget to give your valuable feedback. Go in the comment section and Give us some feedback about it. Inputting the date using C or My website.
Our team check your every Comment per day Because your one feedback helps us in growing Thesmolt
I request you if you have any doubt or question regarding our site, then please don’t hesitate. We always waiting for your Suggestion.
Note:- If you want to Download This article’s in PDF form, then simply go (Top or Bottom of) Right corner and click on the PRINT icon, and it’s saved as a PDF of Inputting the date using C
C program to Display Current Date and Time
For further questions, you can contact us Via mail [email protected] otherwise, Our Help Page and Contact us Page, which is included below. I hope I’ll able to say all the possible ways to reach us. Or Download My Android Application Below Download Button.