Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- char* extract(char* input);
- //hätte ich noch verwenden sollen
- void extract2(char* input, char** output);
- char* bisDp (char* input);
- //giebt den suffix nach :: aus
- //1. wenn nich das ende eines Strings, gehe bi s:
- //2.wenn nach : noch ein : kommt, printe den rest aus
- char* extract(char* input){
- while(*input != '\0'){
- input= bisDp(input);
- input++;
- if(*input != ':'){
- printf("\n%s\n", input);
- break;
- }
- input++;
- }
- return input;
- }
- //geht durch string bis :
- char* bisDp(char* input){
- while(*input != ':' && *input != '\0'){
- input++;
- }
- return input;
- }
- //Test
- typedef enum{
- OK,
- FAIL
- } Test;
- Test testExtract(char* input, char* expection){
- Test t;
- int ret;
- ret= strcmp (expection,extract(input));
- if(ret == 0){
- t= OK;
- }else{
- t= FAIL;
- }
- return t;
- }
- typedef struct {
- char* input;
- char* expection;
- } TestCase;
- void runTests(int no, TestCase test[]){
- Test t;
- int i;
- for(i= 0; i < no; i++) {
- printf("Test %d: ", i);
- t = testExtract(test[i].input, test[i].expection);
- if(OK == t)
- printf("OK \n");
- if(FAIL == t)
- printf("FAIL \n");
- }
- }
- int main(){
- const int testNo =4 ;
- TestCase tests[4] = {
- {"Ha::ll::o", "o"},
- {"47::11", "11"},
- {"Hall::o", "o"},
- {"H::llo", "llo"}
- };
- runTests(testNo,tests);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement