Created
October 10, 2018 12:07
-
-
Save mmathys/e54025aad2ca9088d787b85cc6e19de6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
struct Tuple { | |
char* firstWord; | |
int wordCount; | |
}; | |
struct Tuple processString(char* string) { | |
printf("our string is: %s and total length %i\n", string, strlen(string)); | |
int wordCount = 0; | |
for(int i = 0; i < strlen(string); i++) { | |
if(string[i] != ' ') wordCount++; | |
else break; | |
} | |
char firstWord[wordCount]; | |
for(int i = 0; i < wordCount; i++) { | |
firstWord[i] = string[i]; | |
} | |
struct Tuple t = { | |
firstWord, wordCount | |
}; | |
return t; | |
}; | |
void test(char* string) { | |
struct Tuple t = processString(string); | |
printf("'%s' -> ('%s', %i)\n", string, t.firstWord, t.wordCount); | |
} | |
int main(int argc, char* argv[]) { | |
test("lorem ipsum"); | |
test("ay ipsum"); | |
test(". ipsum"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment