Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<time.h>
- #include"datastructure.h"
- #include"datetime.h"
- #include<stdlib.h>
- #include<stdio.h>
- #include<string.h>
- #include"tools.h"
- #include<ctype.h>
- char *pStd;
- char *pMin;
- char *pSek;
- char *pos;
- char *lp;
- int Std,Min,Sek;
- int count;
- char c;
- int len;
- int i;
- char *zeit;
- char strTime[9];
- int checkZeit;
- int checkZeit2;
- void getTime(char * Text,TTime * lp)
- {
- do
- {
- //Asking for input, text contains format specification
- printf("%s", Text);
- lp->minute = atoi(NULL);
- lp->second = atoi(NULL);
- lp->hour = atoi(NULL);
- //Fgets to get the string
- fgets(strTime,9,stdin);
- clearBuffer();
- //checking if time is legit
- checkZeit2 = (checkTime(lp, 1 , strTime));
- //as the name says, converting string to actual time format
- convertStringToTime(strTime,lp);
- if(!checkZeit2)
- {
- printf("Falsche Eingabe! Format (hh:mm:ss oder mm:ss)\n Fortfahren mit Enter");//wrong input
- clearBuffer();
- }
- //checking if the value of the integers is right
- checkZeit = checkTime(lp, 0 , strTime);
- // error if not right
- if(!checkZeit)
- {
- printf("Falsche Eingabe! Format (hh:mm:ss oder mm:ss)\n Fortfahren mit Enter");
- clearBuffer();
- }
- }
- while(checkZeit != checkZeit2 );
- }
- void convertStringToTime(char * strTime , TTime * Zeit)
- {
- //initialising pointers
- char * pStd = NULL ;
- char * pMin = NULL ;
- char * pSek = NULL ;
- if (isdigit(strTime[0]))
- {
- pStd = &strTime[0];
- pMin = ((strchr(strTime, ':')+1));
- pSek = ((strrchr(strTime, ':')+1));
- Std = atoi(pStd);
- Min = atoi(pMin);
- Sek = atoi(pSek);//finding the ':' in the string, placing pointer for hourstring to strTime[0]'s address
- //if no hours entered the pointers have to change
- if(pSek == NULL)
- {
- pSek = pMin;
- pMin = pStd;
- pStd = atoi(NULL);
- }
- //trying to write the value into the struct
- if (pStd)
- lp->hour = Std; //compile error: request for member hour in sth not a union or structure
- if (pMin)
- lp->minute = Min;//compile error: request for member hour in sth not a union or structure
- if (pSek)
- lp->second = Sek;//compile error: request for member hour in sth not a union or structure
- }
- }
- int checkTime(TTime * lp ,int truth, char * strTime)
- {
- int i= 0;
- //checking int
- if(truth == 0)
- {
- if((lp->second > 60)||(lp->minute > 60 )||(lp->hour >99))
- return 0;
- else
- return 1;
- }
- //checking string format
- if(truth == 1)
- {
- while(*(strTime + i))
- {
- if(((*(strTime + i) < '0') || (*(strTime + i) > '9' )) && (*(strTime + i) != ':'))
- {
- return 0;
- }
- i++;
- }
- return 1;
- }
- return checkZeit;
- }
- void printTime(TTime * lp)
- {
- //Ausgabe der Zeit
- printf("%02i:%02i:%02i", lp->hour, lp->minute , lp ->second );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement