Exemplo n.º 1
0
static void numericdate(const char *date,int *year_rtn,int *month_rtn,int *day_rtn)
  {
  int x;
  int year=0;
  int month=0;
  int day=0;
  for(x=0;x!=8;++x)
    if(date[x]<'0' || date[x]>'9')
      {
      fprintf(stderr,"Bad date format\n");
      exit(-1);
      }
  year=year*10+*date++-'0';
  year=year*10+*date++-'0';
  year=year*10+*date++-'0';
  year=year*10+*date++-'0';
  month=month*10+*date++-'0';
  month=month*10+*date++-'0';
  day=day*10+*date++-'0';
  day=day*10+*date++-'0';
  --month;
  --day;
  if(checkdate(year,month,day))
    {
    fprintf(stderr,"Bad date format\n");
    exit(-1);
    }
  *year_rtn=year;
  *month_rtn=month;
  *day_rtn=day;
  }
Exemplo n.º 2
0
int isOlder(char *dob1, char *dob2) {
	int day1, day2, month1, month2, year1, year2, flag;
	if (dob1[2] != '-' || dob1[5] != '-' || dob2[2] != '-' || dob2[5] != '-')
		return(-1);
	day1 = (dob1[0] - '0') * 10 + (dob1[1] - '0');
	day2 = (dob2[0] - '0') * 10 + (dob2[1] - '0');
	month1 = (dob1[3] - '0') * 10 + (dob1[4] - '0');
	month2 = (dob2[3] - '0') * 10 + (dob2[4] - '0');
	year1 = (dob1[6] - '0') * 1000 + (dob1[7] - '0') * 100 + (dob1[8] - '0') * 10 + (dob1[9] - '0');
	year2 = (dob2[6] - '0') * 1000 + (dob2[7] - '0') * 100 + (dob2[8] - '0') * 10 + (dob2[9] - '0');
	flag = checkdate(day1, day2, month1, month2, year1, year2);
	if (flag != -1)
	{
		if (year1<year2)
		{
			return(1);
		}
		else if (year1>year2)
		{
			return(2);
		}
		else
		{
			if (month1<month2)
				return(1);
			else if (month1>month2)
				return(2);
			else
			{
				if (day1<day2)
					return(1);
				else if(day1>day2)
					return(2);
				else
					return(0);
			}
		}
	}
	else
	return(-1);

}
int main(){
char s[100];
int a,i=1;
while(i){
    printf("1.Press 1 to check integer\n2.Press 2 to check mobile number\n");
    printf("3.Press 3 to check 12 digit account number\n4.Press 4 to check password with at least 1 integer,1 upper,1 lower and 1 special\n");
    printf("5.Press 5 to check date as dd/mm/yyyy\n6.Press 6 to exit\n");
    scanf("%d",&a);
    if(a<=6 && a>=1){
        switch(a){
            case 1: printf("Enter Integer\n");
                    scanf("%s",s);
                    checkinteger(s);
                    break;
            case 2: printf("Enter Mobile number\n");
                    scanf("%s",s);
                    checkmobileno(s);
                    break;
            case 3: printf("Enter Account number ");
                    scanf("%s",s);
                    checkaccountno(s);
                    break;
            case 4: printf("Enter Password\n");
                    scanf("%s",s);
                    checkpassword(s);
                    break;
            case 5: printf("Enter Date\n");
                    scanf("%s",s);
                    checkdate(s);
                    break;
            case 6: printf("Thank you for using the program\n");
                    i=0;
        }
    }
    else{
        printf("Wrong input,Please try once more\n");
    }
}
return 0;
}
Exemplo n.º 4
0
int main()
{
    char read;
    char cislo[80], mod[10];
    char * pom1,* pom2;
    long rodc, c;
    int i=0, modulo, year, month, day;
    
    printf("Enter an identification number:\n");
    while((read=getchar()) != '\n'){
        strcpy(&cislo[i], &read);
        i++;
    }
    cislo[i] = '\0';
    
    
    if(strlen(cislo) != 11){
        printf("The string is not an identification number.\n");
        return EXIT_FAILURE;
    }
    
    
    for(int j=0; j<10; j++){
        if(j ==6){
            if(cislo[j] != '/'){
                printf("The string is not an identification number.\n");
                return EXIT_FAILURE;
            }
        j++;
        }
        if(isdigit(cislo[j]) !=1){
            printf("The string is not an identification number.\n");
            return EXIT_FAILURE;
        }
    }
    
    pom1 = strtok(cislo, "/");
    pom2 = pom1;
    pom1 = strtok (NULL, "/");
    
    strcat(pom2, pom1);
    pom2[10] = '\0';
    strncpy(mod, pom2, 9);
    mod[9] = '\0';
    
    rodc = strtol(mod, NULL, 10);
    c = strtol(&pom2[9], NULL, 10);
    
    modulo = rodc % 11;
    
    if (modulo == 10) modulo = 0;
    
    if (modulo != c){
        printf("The string is not an identification number.\n");
        return EXIT_FAILURE;
    }

    year = getintfromstring(pom2, 0);
    month = getintfromstring(pom2, 2);
    day = getintfromstring(pom2, 4);
    
    if(checkdate(year,month,day) != EXIT_SUCCESS){
        printf("The string is not an identification number.\n");
        return EXIT_FAILURE;
    }
    else printf("The string could be an identification number.\n");

	return 0;
}
Exemplo n.º 5
0
int parsedate(char *date,const char *s)
  {
  int year= -1, month= -1, day= -1;
  int week=0;
  long x;
  char mbuf[32];
  date[0]=0;
  while(*s==' ' || *s=='\t' || *s=='\n' || *s==',' || *s=='/' || *s=='\'') s++;
  if(!*s) return -1; 

  if((*s=='w' || *s=='W') && (s[1]==' ' || s[1]=='\t' || s[1]>='0' && s[1]<='9'))
    {
    ++s;
    week=1;
    }

  /* Look for month (or skip over day of week) */
  if(!week)
    {
    if(*s>='a' && *s<='z' || *s>='A' && *s<='Z')
     {
     for(x=0;
         (*s>='A' && *s<='Z' || *s>='a' && *s<='z') && x!=3;
         x++,s++)
      mbuf[x]=(0x5F&*s)+'a'-'A';
     mbuf[x]=0; mbuf[0]&=0x5F;
     while(*s>='A' && *s<='Z' || *s>='a' && *s<='z') s++;
     for(x=0;x!=12;x++) if(!strcmp(mbuf,months[x]))
      {
      month=x+1;
      break;
      }
     }
    while(*s==' ' || *s=='\t' || *s=='\n' || *s==',' || *s=='/' || *s=='\'') s++;
    if(!*s) return -1; 

    /* Look for month again */
    if(*s>='a' && *s<='z' || *s>='A' && *s<='Z')
     {
     for(x=0;
         (*s>='A' && *s<='Z' || *s>='a' && *s<='z') && x!=3;
         x++,s++)
      mbuf[x]=(0x5F&*s)+'a'-'A';
     mbuf[x]=0; mbuf[0]&=0x5F;
     while(*s>='A' && *s<='Z' || *s>='a' && *s<='z') s++;
     for(x=0;x!=12;x++) if(!strcmp(mbuf,months[x]))
      {
      month=x+1;
      break;
      }
     }
    }

  while(*s==' ' || *s=='\t' || *s=='\n' || *s==',' || *s=='/' || *s=='\'') s++;
  if(!*s) return -1; 
  if(month!= -1) goto gotmonth;

  /* Look for month */
  if(*s>='0' && *s<='9')
   {
   month=0;
   while(*s>='0' && *s<='9') month=month*10+*(s++)-'0';
   }
  while(*s==' ' || *s=='\t' || *s=='\n' || *s==',' || *s=='/' || *s=='\'') s++;
/*  if(!*s) return -1; */

  gotmonth:

  /* Look for day */
  if(!week)
    {
    if(*s>='0' && *s<='9')
      {
      day=0;
      while(*s>='0' && *s<='9') day=day*10+*(s++)-'0';
      }
    while(*s==' ' || *s=='\t' || *s=='\n' || *s==',' || *s=='/' || *s=='\'')
      s++;
    }

  /* Look for year */
  if(*s>='0' && *s<='9')
   {
   year=0;
   while(*s>='0' && *s<='9') year=year*10+*(s++)-'0';
   if(year<50) year+=2000;
   if(year<100) year+=1900;
   }

  /* Fill in current year if none */
  if(year== -1)
   {
   long t=time(NULL);
   struct tm *tm=localtime(&t);
   year=tm->tm_year+1900;
   }

  --month;
  --day;
  if(week) dateofweek(year,month,1,&year,&month,&day);
  if(checkdate(year,month,day)) return -1;
  sprintf(date,"%4.4d%2.2d%2.2d",year,month+1,day+1);
  return 0;
  }