Created
May 21, 2014 13:14
-
-
Save castaneai/69e3e60f9d667be8d39c to your computer and use it in GitHub Desktop.
split関数のテスト
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 <memory.h> | |
#include <string.h> | |
char** split(char* originalString, int stringNum) | |
{ | |
int i; | |
char** stringArray; | |
char* tp; | |
stringArray = (char**) malloc(stringNum * sizeof(char*)); | |
for (i = 0; i < stringNum; i++) { | |
stringArray[i] = (char*) malloc(1024 * sizeof(char)); | |
} | |
i = 0; | |
tp = strtok(originalString, ","); | |
stringArray[i] = tp; | |
i++; | |
while (tp != NULL) { | |
tp = strtok(NULL, ","); | |
if (tp != NULL) { | |
stringArray[i] = tp; | |
i++; | |
} | |
} | |
return stringArray; | |
} | |
int main(void) | |
{ | |
int i; | |
char input [] = "is,this,the,zombie?"; | |
char** arr = split(input, 4); | |
for (i = 0; i < 4; i++) { | |
printf("%s\n", arr[i]); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment