Created
July 8, 2014 06:54
-
-
Save elleryq/ad0c7017edb8b4fca43a to your computer and use it in GitHub Desktop.
Split string according to space and convert each token to uppercase.
This file contains hidden or 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> | |
| char* strupper(char* s) { | |
| char* t = strdup(s); | |
| char* p = t; | |
| while( *p ) { | |
| *p = toupper(*p); | |
| p++; | |
| } | |
| return t; | |
| } | |
| int tokenize(char* s) { | |
| char *t = strdup(s); | |
| char *p = strtok(t, " "); | |
| printf("%s\n", strupper(p)); | |
| while((p=strtok(NULL, " "))) { | |
| printf("%s\n", strupper(p)); | |
| } | |
| } | |
| int main(int argc, char* argv[]) { | |
| tokenize("Hello world"); | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment