I have a main that
I want to use getline to get the user's words after i do a strtok to eliminate these delimiters (" ,.-")

and then find the soundex code of each word and insert the words into my hashtable.
i made an attempt but i was not getting anything. please help.

int main(int argc, char * argv[])
{

//argv takes in whatever the user passes.
//Hashtable dwords;
ifstream fin;
char * info = "/home/jclark/bin/words";// takes in a dictionary from this link.
char * code;
char c[40];
char * pch;
char buff[50];

if((argc > 1)&& !strcmp(argv[1], "-d") && (argc > 2))
{
info = argv[2];
//usrinput = argv[2];
/*cin.getline(usrword, 80);
pch = strtok(argv[2], " ,.-");
cout << "got to the first stuff"<<endl;
while(pch != NULL)
{
cout<< "got into while loop" <<endl;
cin.getline(usrword, 80);
pch = strtok(NULL, " ,.-");
if(pch == NULL)
{
exit(1);
}
}
}*/ //my attempt of the getline strtok stuff
//cout << "this is the end of the loop" <<endl;
//info = usrword;
//i am workign here at the moment to try the strtok
fin.open(info);
if (fin.is_open())
{
//fin.getline(buff, 50);
//pch = strtok(NULL, " ,.-");
fin >> c;
while(!fin.eof())
{

code = soundex(c);
cout << c << " "<< code << endl;
//dwords.insert(c, code);
fin >> c;


}

}
fin.close();
fin.clear();

return 0;
}

line 13: >>if((argc > 1)&& !strcmp(argv[1], "-d") && (argc > 2))

All you need is one check for argc if((argc > 2)&& !strcmp(argv[1], "-d")) Also post a few lines from the text file.

ok the link in the begining of the code has dictionary words
the arg v in the main takes in a sentence from the user and checks it with the dictionary to see whether that word exists.

the -d check is if the user inputs their own sample dictionary after they echo the sentence that they want to check

line 13: >>if((argc > 1)&& !strcmp(argv[1], "-d") && (argc > 2))

All you need is one check for argc if((argc > 2)&& !strcmp(argv[1], "-d")) Also post a few lines from the text file.

Oh, so the user can enter a complete sentence as the command-line arguments.

std::string sentence;
int nc = 1;
if( argc > 1 && strcmp(argv[1], "-d") == 0)
{
     info = argv[2];
     nc = 3;
}
while(nc < argc)
{
    sentence += argv[nc];
    sentence += " ";
    ++nc;
}
This article has been dead for over six months. Start a new discussion instead.