c - segmentation fault core dump after program runs and displays output -
i have made changes program started with: reason getting segmentation error. happens after output , think may have free statement in destroy function. ran through gdb , told me trying access 0x000000d memory location weird because can print out memory location of struct , shows different. know have missed small. appreciated thanks!
had take m code down since on going project in school replies post on once have grade.
you have undefined behavior in code.
take line:
struct person *userone=inputvalues(userone);
here define variable userone
, initialize calling inputvalues
function, pass uninitialized pointer. means inside inputvalues
function, temp
pointer uninitialized, , value indeterminate leading said ub when dereference pointer.
one possible solution define structure variable not pointer, , use when calling inputvalues
, or dynamically allocating structure , pass function. or redesign program not pass argument function @ all, , let function allocate structure.
using uninitialized variables detectable compilers, , can issue warnings it. if don't such warning might want consider enabling more warnings.
Comments
Post a Comment