Zeitstrucktur



  • Guten Tag und frohe rest Ostern erstmal,

    Kurze frage gibt es eine Funktion usw, wo man int mit einer Zeit vergleichen kann. bzw das Int die glütige strucktur einer zeit besitzt ?

    grüße Michael



  • Nimm <time.h> resp. <ctime>

    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    struct tm *tmnow;
    void today(void) {
       time_t tnow;
       time(&tnow);
       tmnow = localtime(&tnow);
       printf("Heute ist der ");
       printf("%d.%d.%d\n",
          tmnow->tm_mday, tmnow->tm_mon + 1, tmnow->tm_year + 1900);
    }
    int main() {
       int tag, monat, jahr;
       unsigned int i=0, tmp;
       printf("Bitte gib Deinen Geburtstag ein!\n");
       printf("Tag : ");
       scanf("%d", &tag);
       printf("Monat : ");
       scanf("%d", &monat);
       printf("Jahr (jjjj) : ");
       scanf("%d", &jahr);
       today();
       if(tmnow->tm_mon < monat) {
          i = 1;
          tmp=tmnow->tm_mon+1-monat;
          monat=tmp+12;
       }
       else {
          tmp=tmnow->tm_mon+1-monat;
          monat=tmp;
       }
       if(monat == 12) {
          monat = 0;
          i = 0;
       }
       printf("Sie sind %d Jahre %d Monate %d Tage alt\n",
          tmnow->tm_year+1900-jahr-i,monat, tmnow->tm_mday-tag);
       return EXIT_SUCCESS;
    }
    

    😉



  • also eine int mit der zeit vergleichen das iss ja ok ich meine das der eingebene int wert in einer erlaubenzeit bewegt nicht das zum 19:59:69 erkannt wird. Ich hab es zwar schon auf einem weg gelöst würde es blos gerne noch vereinfachen.

    bool eingabecheck( string eingabe )
    	{
    	 int anzahlOK = 0, stelleMAX = 50;
    	 for (int i = 0; i < 6; i++)
    	    {
    	     if (isdigit(eingabe[i])) 
    	       {
    		if (eingabe[i] <= stelleMAX)
    		  {
    		   int ersteziffer = eingabe[0];
    		   if ((i == 0)&(ersteziffer < 50)) {stelleMAX = 57;anzahlOK++;}
    		   else if ((i == 0)&&(ersteziffer == 50)) {stelleMAX  = 51;                        anzahlOK++;}
    		   else if ((i == 1)||(i == 3)) {stelleMAX = 53; anzahlOK++;}
    		   else if ((i == 2)||(i == 4)) {stelleMAX = 57; anzahlOK++;}
    		   else if (i == 5) {anzahlOK++;}
    		  }
    	       }
    	    }
    	 if (anzahlOK == 6) {return true;}
    	 else {return false;}
    	}
    

Anmelden zum Antworten