Hi,
Here's my code
#include<iostream>
#include<fstream>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
int cIndex(char *x,char **featlist,int len)
{
int i;
for(i=0;i<len;i++)
if(strcmp(x,featlist[i])==0)
return i;
}
int main(int argc,char *argv[])
{
std::ifstream featFile(argv[1],ios::in);
std::ifstream trainFile(argv[2],ios::in);
// std::ofstream svmFile(argv[3],ios::out);
char line[20000];
char feat[100];
char **featlist;
int i=0,len=0,fl=0,j;
char* x;
int valnum;
while(featFile.good())
{
featFile.getline(feat,100,'\n');
if(featFile.eof()) break;
len++;
}
featFile.clear();
featFile.seekg(0,ios::beg);
// cout<<len<<endl;
featlist=new char*[len];
for (i = 0; i < len; ++i)
featlist[i] = new char[100];
i=0;
while(featFile.good())
{
featFile.getline(feat,100,'\n');
if(featFile.eof()) break;
strcpy(featlist[i],feat);
i++;
}
while(trainFile.good())
{
trainFile.getline(line,20000,'\n');
x=strtok(line," ");
valnum=cIndex(x,featlist,len);
cout<<valnum<<";";
}
trainFile.close();
}
my featFile is of the form
yasuhiro
ali
mdbl
consum
dollar
unrest
protest
mile
mill
ventur
semiconductor
heller
authoris
and my trainFIle is of the form
acq 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0 22:0 23:0 24:0 25:0 26:0 27:0 28:0 29:0 30:0 31:0 32:0 33:0 34:0
acq 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0 22:0 23:0 24:0 25:0 26:0 27:0 28:0 29:0 30:0 31:0 32:0 33:0 34:0
so i basically have to read the training file and replace the first name with an array index...the array index is formed using the featFile...the call to cIndex keeps seg faulting after some iterations.