diff options
Diffstat (limited to 'String.c')
-rw-r--r-- | String.c | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -103,3 +103,30 @@ int String_contains_i(char* s, char* match) { } return 0; } + +char* String_getToken(const char* line, const unsigned short int numMatch) { + const unsigned short int len = strlen(line); + char inWord = 0; + unsigned short int count = 0; + char match[50]; + + unsigned short int foundCount = 0; + + for (unsigned short int i = 0; i < len; i++) { + char lastState = inWord; + inWord = line[i] == ' ' ? 0:1; + + if (lastState == 0 && inWord == 1) + count++; + + if(inWord == 1){ + if (count == numMatch && line[i] != ' ' && line[i] != '\0' && line[i] != '\n' && line[i] != EOF) { + match[foundCount] = line[i]; + foundCount++; + } + } + } + + match[foundCount] = '\0'; + return((char*)strdup(match)); +} |