Back
#include<stdio.h>
#define SIZE 50
int getline(char *s, int lim);
int main()
{
int day, month, year;
char monthname[20];
char line[SIZE];
while (getline(line, sizeof(line)) > 0)
{
if (sscanf(line, "%d %s %d", &day, monthname, &year) ==3)
printf("valid: %s\n", line);
else if (sscanf(line, "%d/%d/%d", &month, &day, &year) ==3)
printf("valid: %s\n", line);
else
printf("invalid: %s\n", line);
}
return 0;
}
int getline(char *s, int lim)
{
int c, i;
i=0;
while(--lim > 0 && (c=getchar()) != EOF && c!='\n')
{ *s++=c; i++; }
if(c=='\n')
{ *s++=c; i++; }
s[i]='\0';
return i;
}
Top |