Re: strtok() Programming Software Development by stercor strtok uses the name of the string on its first invocation, NULL thereafter for the same string. strtok can be confusing at first; it's a good instruction when you know how it works. Re: strtok() help Programming Software Development by Narue strtok isn't that smart. It takes the delimiters you give … Re: strtok() Programming Software Development by somjit{} > strtok uses the name of the string on its first invocation, NULL thereafter for the same string. that sounds good... any code exapmples? Re: strtok() help Programming Software Development by Narue …to stop using it altogether, just understand the weaknesses of strtok. For example, the first two tokens can be easily … any special rules for embedded delimiters. That's where strtok breaks down and you need to use something else. …But it's possible to start where strtok stopped and do the split manually: [code=cplusplus] char … Re: strtok Programming Software Development by Ancient Dragon …(b2b_rates_address,1000,in_fp) != NULL ) { if( (ptr = strtok(b2b_rates_address,",")) { strcpy(rates_details[j].ig1, ptr); printf(&…%s\n",rates_details[j].ig2 ); if( (ptr = strtok(NULL, ",")) { strcpy(rates_details[j].ig3, ptr… Re: strtok Programming Software Development by dkalita … then u must pass NULL in the 1st argument to strtok() after making the first call to it with the actual… string. its like: [CODE] char *tok = strtok(str, " "); //next token u can get by tok… = strtok(NULL, " "); [/CODE] U are passing the input string … Re: strtok Programming Software Development by dkalita …pass NULL in the 1st argument to strtok() after making the first call to … string. its like: [CODE] char *tok = strtok(str, " "); //next token u can… get by tok = strtok(NULL, " "); [/CODE] U are … the time. read manual of strtok (type "man strtok" in linux)[/QUOTE] Sorry… strtok Programming Software Development by hwoarang69 …statment. i think bc i am not using strtok right ------------------------------------------------code---------------- while(fgets(line, 20,…in this if statment { tptr2 = strtok(line, " "); tptr2 = strtok(NULL, ""); if(tptr2 … Re: strtok Programming Software Development by Banfa When you called strtok at line 3 it replaced the ':' in line with a '\…" and leaves tptr pointing at line. If you called strtok a second time then tptr will be updated to point…;.word". On the whole I would recomend not using strtok at all because of this destruction of data and because… strtok Programming Software Development by sjgriffiths …!= NULL ) { strcpy(rates_details[j].ig1, strtok(b2b_rates_address,",")); printf("rates_details[j].ig7 …[j].ig1 ); strcpy(rates_details[j].ig2,strtok(NULL,",")); printf("rates_details[j…[j].ig2 ); strcpy(rates_details[j].ig3,strtok(NULL,",")); printf("rates_details[j… Re: strtok() Programming Software Development by deceptikon …gt; on another note, what is strtok() good/designed for? Tokenizing strings. But… kind of hoping for an actual argument against strtok() rather than the usual rehashed "it … you can't make a copy then clearly strtok() is the wrong choice. I'm not… that you should *always* use strtok(), but anyone who says strtok() is evil and should never be… Re: strtok help Programming Software Development by satys.sara …// Extract the start Pax name.number strtok(tempNameNumber, "-")); strcpy(endingRange, … the ending Pax name.number strtok(NULL,"-")); } tempNameNumber=strtok(NULL, delimiters); -->… Re: strtok help Programming Software Development by satys.sara …// Extract the start Pax name.number strtok(tempNameNumber, "-")); strcpy(endingRange, … the ending Pax name.number strtok(NULL,"-")); } tempNameNumber=strtok(NULL, delimiters); -->… Re: strtok Programming Software Development by Narue >this field may/may not be empty strtok ignores empty fields, so if that field is empty, you're actually processing a null pointer because there are fewer fields than you're expecting. If you want to get an empty string for the empty field, don't use strtok. Re: strtok() help Programming Software Development by Narue … be posible to find the >location at where strtok left like an array index? Possible, yes. Recommended,…Right, you're getting well past the point where strtok is a suitable solution, but you can fix … 12:12:12"; char *genre = std::strtok ( info, " " ); char *category = std::strtok ( 0, " " ); char *name =… Re: strtok() Programming Software Development by deceptikon …a pointer */ char *tok = strtok(src, " "); while (tok) { …puts(tok); tok = strtok(NULL, " "); } return 0; … single most important thing to remember about strtok() is that it *modifies the source string… Re: strtok help Programming Software Development by deceptikon … be problematic. However, you can use `strtok` to split the string on `&` like this: ….1&9.1&11.1/"; char *tok = strtok(s, "&"); while (tok != NULL) { char *sep …else { // No range printf("%s\n", tok); } tok = strtok(NULL, "&"); } strtok Programming Software Development by sjgriffiths … size = 0; size < b2b_data_drill_nNoSelect; size++ ) { if (size == 1 ) { ptoken = strtok(pOutData, ";" ); while( ptoken != NULL ) { printf ("Results 2nd…[size] ); printf ("ptoken:%s\n", ptoken ); ptoken = strtok(NULL, ";" ); } } }[/code] Re: strtok Programming Software Development by Ancient Dragon I would copy the string into some local buffer because strtok() will replace the ; with null characters, which destroys the original string. [code] char temp[255]; strcpy(temp,*pOutData); pToke = strtok(temp,","); // rest of program here [/code] Re: strtok Programming Software Development by sjgriffiths …,pOutData[size]); //printf("Temp = %s\n", temp); ptoken = strtok(temp, ";" ); while( ptoken != NULL ) { printf ("Results 2nd…;, pOutData[size] ); printf ("ptoken:%s\n", ptoken ); ptoken = strtok(NULL, ";" ); } } } [/code] any ideas? Re: strtok Programming Software Development by Ancient Dragon …,pOutData[1]); //printf("Temp = %s\n", temp); ptoken = strtok(temp, ";" ); while( ptoken != NULL ) { printf ("Results 2nd…;, pOutData[1] ); printf ("ptoken:%s\n", ptoken ); ptoken = strtok(NULL, ";" ); } [/code] Re: strtok() help Programming Software Development by opposition … it would be posible to find the location at where strtok left like an array index? because the second snippet of…"[/CODE] if i could get the index of where strtok would have stopped I could just use a while(not… till its false, also would i be able to use strtok again after ive done this loop to include to remaining… strtok Programming Software Development by leeba … of errors and I am having no luck. I think strtok is the main problem but not sure how else to…())==' ') spaceCount++; if ((c=getchar())=='\n') } for (i=0; dollar[i]=strtok(c," "), i++); printf("$ \t IS\n"… Re: strtok Programming Software Development by Ancient Dragon … array and save the characters in it. >>strtok(c," "), strtok() works on character arrays, not single characters. Passing… Re: strtok Programming Software Development by leeba Thank you both. I ended up giving up on the strtok and using scanf instead of getchar. But i will need …later in my curse strtok. so Thank you anyways. Do either of you have experience… Re: strtok help Programming Software Development by Ancient Dragon … memory for data then copy the return value of strtok() into it. Warning! The following code has not… NULL) { while( fgets(iobuf, sizeof(iobuf), fp) != NULL) { ptr = strtok(iobuf,' '); while(ptr != NULL) { node = malloc(sizeof(struct token)); node… Re: strtok() Programming Software Development by somjit{} … on the delimiter u provide... [c89 standard strtok](http://www.cplusplus.com/reference/clibrary/cstring/strtok/).. should give u an idea... $ is…-using-sscanf) tells u something about the bad sides of strtok... u can take a look at it too. Re: strtok() Programming Software Development by somjit{} … intentionally goes against its design a lot of ppl suggest strtok() for parsing... just shows how many ppl dont read (what… stuff out.. so thats good :) on another note, what **is** strtok() good/designed for? there was this part in that page… : > The correct way to use strtok is to pass it a copy of the string unless… Re: strtok help Programming Software Development by Ancient Dragon … the digits from the string returned by strtok(), and stops converting when it encounters anything…amp;9.1&11.1/"; char *ptr = strtok(str, "&"); while (ptr != NULL)… if (*p == '*') p = extract(++p); ptr = strtok(NULL, "&"); } } Re: Strtok() Programming Software Development by wal99d …]; int i=0; all = "ls -l"; res[i]= strtok(all," "); while (res[i] != NULL){ res[++i…]= strtok(NULL," "); } execvp(res[0],&res[0]); ---> …