cant call my function

char findwords(char words[],char * pointer); //declare the find words function




int main()
{
int test;
char words[100]; //the users response
char * pointer; //a pointer to use for strotk
cout << "die monster !"; //a guards initial dialouge
cin.getline (words,100);//getting the users string
getwords(char words, char * pointer)
cin >> test;
return 0;
}



char findwords(char words[],char * pointer)
{
printf ("Splitting string \"%s\" into tokens:\n",words); //print wich string is going to be split
pointer = strtok (words," ,.-"); // use strotk to split the words up
while (pointer != NULL) //create a while loop to print out the seperated words
{
printf ("%s\n",pointer);
pointer = strtok (NULL, " ,.-");
}

return 0;
}






for some reason the program crashes as soon as i try to call my function how should i call this function
Last edited on
You don't call findwords() in the code you've posted.
as said by kbw you haven't called function findwords(char[],char*)

Also there is invalid pointer conversion,you should be passing reference.
closed account (zb0S216C)
Dougfunny wrote:
getwords(char words, char * pointer)

A function cannot be declared within the scope of another function. Also, I think you got your function call wrong. Did you mean: findwords( words, pointer )?

As Cody39e said, you should be passing by reference. However, I would replace the second parameter of findwords with: char *&pointer. If you don't know already, this is a reference to a pointer. It basically ensures that you're working with the original argument given to the function, not a copy.

Wazzak
Last edited on
Topic archived. No new replies allowed.