开发者

C Segmentation Fault problem

Let me start by saying that I've been programming in Java and C# for the last 5 years or so, so my C skills are very rusty.

I'm getting a segmentation fault, and I'm not quite sure why. Using gdb, I was able to find the line causing the fault, but I'm not sure what the problem is. Please help :)

I read in a integer value from a file, it's a number of seconds. Say I read save that value into char token[100]...

time_type sim_time;
char *s;
unsigned long time_sim;
s = token;
time_sim = strtoul(s,0,10);
int_to_time(time_sim, &sim_time);

Add_Event(eventId, agentId, &sim_time);

time_type is a struct, it has a bunch of fields. here's the declaration of int_to_time:

void int_to_time(unsigned long, struct time_type*);

now here's the declaration of Add_Event:

void  Add_Event(int, int, struct time_type*);

The call to int_to_time goes fine, but the next call to Add_Event gives a segmentation fault for sim_开发者_如何学Pythontime. What am I doing wrong?

Thanks in advance. I tried not to include unnecessary code, but if I didn't include enough, please let me know.


I don't know what library your time_type and int_to_time are coming from, but I would look at its docs and see if you need to initialize a time_type in some way before using it as the destination of int_to_time or something like that. The code isn't blatantly wrong on its face, but it's hard to tell without seeing more code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜