Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.44 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5.  
  6. char* extract(char* input);
  7. //hätte ich noch verwenden sollen
  8. void extract2(char* input, char** output);
  9. char* bisDp (char* input);
  10.  
  11. //giebt den suffix nach :: aus
  12. //1. wenn nich das ende eines Strings, gehe bi s:
  13. //2.wenn nach : noch ein : kommt, printe den rest aus
  14. char* extract(char* input){
  15.  
  16. while(*input != '\0'){
  17.  
  18.     input= bisDp(input);
  19.  
  20.     input++;
  21.  
  22.     if(*input != ':'){
  23.  
  24.             printf("\n%s\n", input);
  25.             break;
  26.         }
  27.  
  28.         input++;
  29.  
  30.     }
  31.     return input;
  32. }
  33.  
  34. //geht durch string bis :
  35. char* bisDp(char* input){
  36. while(*input != ':' && *input != '\0'){
  37.     input++;
  38.     }
  39.  
  40. return input;
  41. }
  42.  
  43. //Test
  44. typedef enum{
  45. OK,
  46. FAIL
  47. } Test;
  48.  
  49. Test testExtract(char* input, char* expection){
  50. Test t;
  51. int ret;
  52.  
  53.    ret= strcmp (expection,extract(input));
  54.  
  55.    if(ret == 0){
  56.         t= OK;
  57.  
  58.    }else{
  59.        t= FAIL;
  60.        }
  61.  
  62.     return t;
  63. }
  64.  
  65. typedef struct {
  66. char* input;
  67. char* expection;
  68. } TestCase;
  69.  
  70. void runTests(int no, TestCase test[]){
  71. Test t;
  72. int i;
  73.  
  74. for(i= 0; i < no; i++) {
  75. printf("Test %d: ", i);
  76. t = testExtract(test[i].input, test[i].expection);
  77. if(OK == t)
  78. printf("OK \n");
  79. if(FAIL == t)
  80. printf("FAIL \n");
  81.     }
  82. }
  83.  
  84.  
  85. int main(){
  86.  
  87.     const int testNo =4 ;
  88. TestCase tests[4] = {
  89. {"Ha::ll::o", "o"},
  90. {"47::11", "11"},
  91. {"Hall::o", "o"},
  92. {"H::llo", "llo"}
  93. };
  94. runTests(testNo,tests);
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement