Another stuct problme

P

Potatoman

struct b{//elements};

struct b* funcfoo(){
struct b* p={0};
//do something with p
return p;
}
int main(){
struct b*p=//call funcfoo
printf(*%d%s*,p->inte,p->str);
return 0;
}

///////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
SSSSSSEEEEEGMENTATION FAULTTTTT
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\//////////////////////////////////////////////
I am sure you know why ? This is a reapeated error I wasn't able to
memorize. It's on others next to me not me anyway, hehe. Thanx
 
C

Chris Dollin

Potatoman said:
struct b{//elements};

struct b* funcfoo(){
struct b* p={0};
//do something with p
return p;
}
int main(){
struct b*p=//call funcfoo
printf(*%d%s*,p->inte,p->str);
return 0;
}

///////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
SSSSSSEEEEEGMENTATION FAULTTTTT
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\//////////////////////////////////////////////
I am sure you know why ? This is a reapeated error I wasn't able to
memorize. It's on others next to me not me anyway, hehe. Thanx

What you've shown us is not compilable code, so it doesn't segfault.

Guessing wildly at a fix, I'd say that someone has tried to dereference
a null pointer. Bad dog. Null biscuit.
 
B

Barry Schwarz

struct b{//elements};

struct b* funcfoo(){
struct b* p={0};
//do something with p

It depends on what you do with p. Unless you assign a different value
to p (such as by using malloc), the printf in main will always yield
undefined behavior. In this case, you are lucky that this particular
type of undefined behavior yields a segmentation fault.
return p;
}
int main(){
struct b*p=//call funcfoo
printf(*%d%s*,p->inte,p->str);
return 0;
}

///////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
SSSSSSEEEEEGMENTATION FAULTTTTT
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\//////////////////////////////////////////////
I am sure you know why ? This is a reapeated error I wasn't able to
memorize. It's on others next to me not me anyway, hehe. Thanx


Remove del for email
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,181
Messages
2,570,970
Members
47,537
Latest member
BellCorone

Latest Threads

Top