int isOlder(char *dob1, char *dob2) {
    Date date1, date2;
    if (isValidDateFormat(dob1) && isValidDateFormat(dob2)) {
        date1 = getDateFromString(dob1);
        date2 = getDateFromString(dob2);
        if (isValidDate(date1) && isValidDate(date2)) {
            return structCompare(date1, date2);
        }
        else return -1;
    }
    else return -1;
}
extern short getDate(char const *pPrompt, TDate **ppReturnDate)
{
   char aUserInput[12];
   int numberOfSuccessfullyReadValues;
   TDate * pTempDate;

   printf("%s", pPrompt);

   numberOfSuccessfullyReadValues = scanf("%11[^\n]", aUserInput);
   clearBuffer();

   if (numberOfSuccessfullyReadValues == 1)
   {
      pTempDate = calloc(1, sizeof(TDate));

      if (getDateFromString(aUserInput, pTempDate) == 1)
      {
         *ppReturnDate = calloc(1, sizeof(TDate));
         if (*ppReturnDate)
         {
            (*ppReturnDate)->day        = (*pTempDate).day;
            (*ppReturnDate)->month      = (*pTempDate).month;
            (*ppReturnDate)->year       = (*pTempDate).year;
            //(*ppReturnDate)->dayOfWeek  = (*tmpDate).dayOfWeek;

            free(pTempDate);

            return 1;
         }
      }
   }

   return 0;
}
static short loadOnePlayerAttribute(const char * pReadStringFromFile, TPlayer* pPlayerToLoad)
{
   char aScanfFormatAsString[100];
   char aReadBuffer[100];


   if(strncmp(pReadStringFromFile, STARTTAG_TEAM_PLAYER_NAME, sizeof(STARTTAG_TEAM_PLAYER_NAME) - 1) == 0)
   {
      sprintf(aScanfFormatAsString, "%s%s%i%s%s", STARTTAG_TEAM_PLAYER_NAME, "%[^<]", MAXNAMELENGTH, "s", ENDTAG_TEAM_PLAYER_NAME);

      if(sscanf(pReadStringFromFile, aScanfFormatAsString, pPlayerToLoad->nameOfPlayer) == EOF)
         return 0;
      if(pPlayerToLoad->nameOfPlayer == '\0')
         return 0;

      return 1;

   } else if(strncmp(pReadStringFromFile, STARTTAG_TEAM_PLAYER_BIRTHDAY, sizeof(STARTTAG_TEAM_PLAYER_BIRTHDAY) - 1) == 0)
   {
      sprintf(aScanfFormatAsString, "%s%s%s", STARTTAG_TEAM_PLAYER_BIRTHDAY, "%[^<]s", ENDTAG_TEAM_PLAYER_BIRTHDAY);

      if(sscanf(pReadStringFromFile, aScanfFormatAsString, aReadBuffer))
         if(getDateFromString(aReadBuffer, pPlayerToLoad->birthday))
            return 1;

   } else if(strncmp(pReadStringFromFile, STARTTAG_TEAM_PLAYER_JERSEYNUMBER, sizeof(STARTTAG_TEAM_PLAYER_JERSEYNUMBER) - 1) == 0)
   {
      sprintf(aScanfFormatAsString, "%s%s%s", STARTTAG_TEAM_PLAYER_JERSEYNUMBER, "%3hu", ENDTAG_TEAM_PLAYER_JERSEYNUMBER);

      if(sscanf(pReadStringFromFile, aScanfFormatAsString, &(pPlayerToLoad->jerseyNumber)) == EOF)
         return 0;
      if(pPlayerToLoad->jerseyNumber > 99)
         return 0;

      return 1;

   } else if(strncmp(pReadStringFromFile, STARTTAG_TEAM_PLAYER_GOALS, sizeof(STARTTAG_TEAM_PLAYER_GOALS) - 1) == 0)
   {
      sprintf(aScanfFormatAsString, "%s%s%s", STARTTAG_TEAM_PLAYER_GOALS, "%3hu", ENDTAG_TEAM_PLAYER_GOALS);

      if(sscanf(pReadStringFromFile, aScanfFormatAsString, &(pPlayerToLoad->numberOfGoals)) == EOF)
         return 0;
      if(pPlayerToLoad->numberOfGoals > 99)
         return 0;

      return 1;
   }

   return 0;
}
Exemple #4
0
//  --------------------------------------------------------------------------------
//  prüft Benutzereingabe eines Datum über Input und schreibt bei Validität die
//  Daten via der Funktion getDateFromString in ein TDate Konstrukt
//  --------------------------------------------------------------------------------
int getDate(char *Titel, TDate *Date) // Einbage = Eingabebaufforderung
{
    *Input = '\0';

    CLEAR_LINE;
    printf("%s ", Titel);
    scanf("%10[^\n qwertzuiopü+*asdfghjklöä#'<>yxcvbnm,_:;MNBVCXYÄÖLKJHGFDSAÜPOIUZTREWQ!""§$%&/()=?`'@€~]", Input);
    clearBuffer();

    if(!getDateFromString(Input, Date)) //rekursiver Aufruf, falls Eingabe nicht valide
    {
        UP(1);
        getDate(Titel, Date);
    }
    else return 1;

    return 0;
}
Exemple #5
0
int main()
{
   TDate Date;
   TTime Time;
   char Input[20];

   do
   {
      clearScreen();
      printf("Geben Sie bitte ein gueltiges Datum ein (dd.mm.yyyy): ");
      *Input = '\0';
      scanf("%19[^\n]", Input);
      clearBuffer();
      if (*Input)
         if (getDateFromString(Input, &Date))
            printf("Das Datum %02i.%02i.%04i ist gueltig!\n",
                   Date.Day, Date.Month, Date.Year);
         else
            printf("Das eingegebene Datum %s ist ungueltig!\n", Input);
      else
         printf("Sie haben nichts eingegeben!\n");
      printf("Geben Sie bitte eine gueltige Uhrzeit ein (st:mi:se): ");
      *Input = '\0';
      scanf("%19[^\n]", Input);
      clearBuffer();
      if (*Input)
         if (getTimeFromString(Input, &Time))
            printf("Die Uhrzeit %02i:%02i:%02i ist gueltig!\n",
                   Time.Hour, Time.Minute, Time.Second);
         else
            printf("Die eingegebene Uhrzeit ist ungueltig!\n");
      else
         printf("Sie haben nichts eingegeben!\n");
   } while (askAgain("Moechten Sie noch einmal (j//n) ? "));
   return 0;
}