#include #include int main() { char * word, * unused; char * cmd = "ls -la &"; char temp[1024]; strcpy( temp, cmd ); /* copy cmd to temp, because strtok() changes input */ word = strtok_r( temp, " \t", &unused ); while ( word != NULL ) /** temp: "ls\0-la\0&" **/ { /** ^ **/ printf( "[%s] %s\n", cmd, word ); /* strcpy() here or save each of the returned pointers */ word = strtok_r( NULL, " \t", &unused ); /* re-entrant */ } printf( "[%s]\n", cmd ); printf( "[%s]\n", temp ); return 0; }