I.You

Hi there,

Please see this code:

typedef struct {
char **item;
char **user;
}Listtype;

int main(int argc, char **argv)
{

....
Listtype List;

...

strdiv(buf, &List);

..

}

void strdiv(char *buf, Listtype *List)
{
...
List->item[0] = strtok(buf, "<>"); <-- HERE

...

The segmentation fault occurs at HERE.

What's wrong

Please tell me what problem is.

Thank you.



Re: Visual C++ Language segmentation fault due to the struct pointers

TilakGopi

Hi,

You didn't either allocate memory to List->item or make it point to a valid memory.Once you do this, you can assign some value to List->item[0] .This might be causing the problem,i guess.

Thanks,

Ch.T.Gopi Kumar.






Re: Visual C++ Language segmentation fault due to the struct pointers

I.You

Thanks a lot!

you're right.

It's solved as just I allocated memory to List-> item.

Best regards.





Re: Visual C++ Language segmentation fault due to the struct pointers

Marius Bancila

Why don't you use std:Tongue Tiedtring instead of char*