Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- static char* _last = NULL;
- char *strtok( char* str, char token ) {
- char *ptr = NULL;
- if ( str ) {
- ptr = str;
- _last = str;
- while ( *_last && *_last != token ) _last++;
- if ( *_last ) *_last = 0;
- else _last = NULL;
- } else {
- if ( _last ) {
- *_last = token;
- _last++;
- ptr = _last;
- while ( *_last && *_last != token ) _last++;
- if ( *_last ) *_last = 0;
- else _last = NULL;
- }
- }
- return ptr;
- }
- int main() {
- char x[] = "alma korte cseresznye a b c";
- char * y = strtok( x, ' ' );
- while( y ) {
- printf( "%s\n", y );
- y = strtok( NULL, ' ' );
- }
- return 0;
- }
RAW Paste Data