Created
May 15, 2013 06:59
-
-
Save ryaninhust/5582111 to your computer and use it in GitHub Desktop.
Extract data from LIBSVM format
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
/* strtok example */ | |
#include <stdio.h> | |
#include <cstring> | |
#include <string> | |
#include <vector> | |
using namespace std; | |
int main () | |
{ | |
char str[] ="1 1:1 2:2 3:3"; | |
char * pch; | |
vector<string> res; | |
pch = strtok (str," "); | |
while (pch != NULL) | |
{ | |
printf ("%s\n",pch); | |
res.push_back(pch); | |
pch = strtok(NULL, " "); | |
} | |
for(int i=0;i < res.size();i++) | |
{ | |
if(i == 0) | |
{ | |
printf("label\n"); | |
} | |
else | |
{ | |
char *tem = new char[5]; | |
char * subpch; | |
strcpy(tem, res[i].data()); | |
subpch = strtok(tem, ":"); | |
while(subpch !=NULL) | |
{ | |
printf("%s\n", subpch); | |
subpch = strtok(NULL, ":"); | |
} | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment