I am using strtok() the string tokenizer
input is like say
"a,b,c,d|12,34,56,78"
I am doing
char * cols;
char * vals;
$char col_val_temp[1024] = {0};
$char col_val[1024] = {0};
cols = strtok(input,"|");
vals = strtok('\0',"|");
// now vals will have "12,34,56,78"
strcpy(col_val_temp,vals);
strcpy(col_val,col_val_temp);
and in the later part of code I am again using strtok on vals but, I see in debugger that suddenly out of no where the value of col_val becomes null while there is data present in col_val_temp. I have not done any operation on col_val string, so I don’t understand why the data in there is getting lost.
Can someone please explain why I am getting this behavior and how to overcome this.
I am stuck because of this.
Thanks !!!
There is (at least) one buffer overrun problem in your code.
You do a
strcpytoseqno.seqnois declared only one character long, so the string terminator will probably overwrite the pointer value ofcols.