char * strtok_mv(char * str, const char * set){ static unsigned char * strtok_n_mv = (unsigned char *) ""; static unsigned char * strtok_s_mv = (unsigned char *) ""; unsigned char *p, *q; int c; unsigned char map[32]; for (c=0; c<32; c++) map[c] = 0; if (str) strtok_s_mv = (unsigned char *) str; p = (unsigned char *) set; while (c = *p++) set_char_map(map, c); p = strtok_s_mv; while (c = *p++) if (!tst_char_map(map, c)) break; if (!c) { strtok_s_mv = strtok_n_mv; return(NULL); } q = p - 1; while (c = *p++) if (tst_char_map(map, c)) break; if (!c) strtok_s_mv = strtok_n_mv; else { strtok_s_mv = p; *--p = 0; } return((char *) q);}
data = string_search(&data[0],'&',TRUE); //null terminate at the &data = string_search(&data[0],'=',FALSE); //point to the right hand side of the '='onoffbutton = data; char * string_search(char * data, const char delimitor, int terminate){ if(data != NULL) { while (*data != delimitor){ data++; } if (terminate) *data=0; //null terminate the string data++; return (data); } else { return NULL; } }
#include <stdio.h>#include <string.h>char str[] = "now # is the time for all # good men to come to the # aid of their country";char delims[] = "#"; char *result = NULL; int main(void){ printf("Hello World in C\n\r"); result = strtok( str, delims ); while( result != NULL ) { printf( "result is \"%s\"\n", result ); result = strtok( NULL, delims ); } fflush(stdout); while(1) { }}