I have a problem with acquiring a date from input as a string, this way:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char day[10], month[2], year[4];
printf("Insert date (mm/dd/yyyy): ");
scanf("%s/%s/%s", day, month, year);
while (! (strlen(day)==2 && strlen(month)==2 && strlen(year)==4) )
{
printf("Invalid format. Retry!\n");
scanf("%s/%s/%s", day, month, year);
}
printf("Date inserted: %s/%s/%s\n", year, month, day);
return 0;
}
When I enter something from input, it stores all the string in the first variable (i.e. day). How can I get it to work properly without using int in the first place?