Skip to content

Instantly share code, notes, and snippets.

@elleryq
Created July 8, 2014 06:54
Show Gist options
  • Save elleryq/ad0c7017edb8b4fca43a to your computer and use it in GitHub Desktop.
Save elleryq/ad0c7017edb8b4fca43a to your computer and use it in GitHub Desktop.
Split string according to space and convert each token to uppercase.
#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