C: strtok on pointer inside a struct?

Note that strtok modifies the string - if your txt pointer is pointing at a read-only string (e.g. A const string literal) then you will get an exception.

You need to allocate the memory for gRow *row ; Then it will work fine, I hope.

I did allocate... the code here is from function that get the pointer after everything already allocated. – Shahar Mar 4 '10 at 11:21.

Strtok modifies the string given to it. If you don't have the right to modify it, you might get a Segmentation Fault. Strdup prevents that by copying the string.

Strtok modifies its first argument. In case 1 looks like you were passing a pointer to char constant which could not be modified. And in case 2 you were passing a modifiable copy of it returned by strdup.

Thanks for your answer. In case 1, this char pointer isn't constant (i didn't defined it as one). So... what makes it happens?

– Shahar Mar 4 '10 at 11:18 @Shaharg: I meant, did you do something like: row->txt = "text"; If yes then you cannot modify what row->txt is pointing to, so you cannot pass row->txt to strtok. – codaddict Mar 4 '10 at 11:31.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions