Created
October 10, 2018 11:59
-
-
Save mmathys/e03f320817e3539b4928e02eced2013b 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\n", string); | |
int wordCount = 0; | |
for(int i = 0; i < sizeof(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