Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1.  
  2. #include<time.h>
  3. #include"datastructure.h"
  4. #include"datetime.h"
  5. #include<stdlib.h>
  6. #include<stdio.h>
  7. #include<string.h>
  8. #include"tools.h"
  9. #include<ctype.h>
  10.  
  11.  
  12. char *pStd;
  13. char *pMin;
  14. char *pSek;
  15. char *pos;
  16. char *lp;
  17. int Std,Min,Sek;
  18. int count;
  19. char c;
  20. int len;
  21. int i;
  22. char *zeit;
  23. char strTime[9];
  24. int checkZeit;
  25. int checkZeit2;
  26.  
  27. void getTime(char * Text,TTime * lp)
  28. {
  29.  
  30.  
  31. do
  32. {
  33. //Asking for input, text contains format specification
  34. printf("%s", Text);
  35.  
  36. lp->minute = atoi(NULL);
  37. lp->second = atoi(NULL);
  38. lp->hour = atoi(NULL);
  39.  
  40. //Fgets to get the string
  41. fgets(strTime,9,stdin);
  42. clearBuffer();
  43.  
  44.  
  45.  
  46. //checking if time is legit
  47. checkZeit2 = (checkTime(lp, 1 , strTime));
  48.  
  49. //as the name says, converting string to actual time format
  50. convertStringToTime(strTime,lp);
  51.  
  52. if(!checkZeit2)
  53. {
  54. printf("Falsche Eingabe! Format (hh:mm:ss oder mm:ss)\n Fortfahren mit Enter");//wrong input
  55. clearBuffer();
  56. }
  57.  
  58. //checking if the value of the integers is right
  59. checkZeit = checkTime(lp, 0 , strTime);
  60.  
  61. // error if not right
  62. if(!checkZeit)
  63. {
  64. printf("Falsche Eingabe! Format (hh:mm:ss oder mm:ss)\n Fortfahren mit Enter");
  65. clearBuffer();
  66. }
  67.  
  68. }
  69. while(checkZeit != checkZeit2 );
  70.  
  71.  
  72. }
  73.  
  74. void convertStringToTime(char * strTime , TTime * Zeit)
  75. {
  76.  
  77. //initialising pointers
  78. char * pStd = NULL ;
  79. char * pMin = NULL ;
  80. char * pSek = NULL ;
  81.  
  82. if (isdigit(strTime[0]))
  83. {
  84. pStd = &strTime[0];
  85. pMin = ((strchr(strTime, ':')+1));
  86. pSek = ((strrchr(strTime, ':')+1));
  87. Std = atoi(pStd);
  88. Min = atoi(pMin);
  89. Sek = atoi(pSek);//finding the ':' in the string, placing pointer for hourstring to strTime[0]'s address
  90.  
  91.  
  92.  
  93. //if no hours entered the pointers have to change
  94. if(pSek == NULL)
  95. {
  96. pSek = pMin;
  97. pMin = pStd;
  98. pStd = atoi(NULL);
  99. }
  100.  
  101. //trying to write the value into the struct
  102. if (pStd)
  103. lp->hour = Std; //compile error: request for member hour in sth not a union or structure
  104. if (pMin)
  105. lp->minute = Min;//compile error: request for member hour in sth not a union or structure
  106. if (pSek)
  107. lp->second = Sek;//compile error: request for member hour in sth not a union or structure
  108.  
  109. }
  110. }
  111. int checkTime(TTime * lp ,int truth, char * strTime)
  112. {
  113.  
  114. int i= 0;
  115. //checking int
  116. if(truth == 0)
  117. {
  118.  
  119. if((lp->second > 60)||(lp->minute > 60 )||(lp->hour >99))
  120. return 0;
  121. else
  122. return 1;
  123. }
  124.  
  125. //checking string format
  126. if(truth == 1)
  127. {
  128.  
  129. while(*(strTime + i))
  130. {
  131. if(((*(strTime + i) < '0') || (*(strTime + i) > '9' )) && (*(strTime + i) != ':'))
  132. {
  133.  
  134. return 0;
  135.  
  136. }
  137.  
  138. i++;
  139. }
  140.  
  141. return 1;
  142. }
  143.  
  144. return checkZeit;
  145. }
  146.  
  147. void printTime(TTime * lp)
  148. {
  149. //Ausgabe der Zeit
  150. printf("%02i:%02i:%02i", lp->hour, lp->minute , lp ->second );
  151.  
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement