i'm trying to get the last word of the sentence using strtok.. i tried this :

while (tok != NULL)
    tok = strtok (NULL, " ");
    if((tok != NULL) && (strtok(NULL, " ")==NULL))
            printf("%s", tok);

kinda doesn't work... anyone knows why?
Yes, tok is a char * pointer..

>>anyone knows why?

how about something like this:

char* lastWord = NULL;
while( tok != NULL )
   lastWord = tok;
   tok = strtok(NULL, " ");
printf("%s\n", lastWord);

that looks like an obvious solution now...

you might have to add code to bypass all other white space (spaces and tabs) because I don't think strtok will do that. Example:

"No     is        the          time       "

kinda doesn't work... anyone knows why?

[edit] AD solved that problem already [/edit]

Anyway, if you're using C++, why not use std::strings, find() and substr()?

#include <iostream>
#include <string>

int main ()
  std::string str = "This is a line of text";
  int lastspace= str.find_last_of(' ')  ;
  std::cout << str.substr(lastspace+1 ,str.size()-lastspace ) << "\n";
  return 0;

output: text

but that doesn't work when there is trailing white space. need to add a little code to trim trailing white space.

Yes you're right of course