For an assignment I have to code up 6 functions that each do a different task. In two of my functions, I am seg faulting and I don't know why. I feel like the solutions are obvious, but I just can't see them. I'm still a beginner when it comes to programming. Here are the two functions:
I don't see the cause in parseInt on casual inspection, although long double main's observation is certainly likely. There a couple other bugs in parseInt. If the condition on line 15 evaluates to true, ptr needs to be freed or you will be leaking memory.
Also, according to the loop condition on line 8 in parseInt, number will be 0 when the loop that begins on line 20 is reached. If number is 0, what is the result of that loop?
In toUnsignedInt you never point sum anywhere, but treat it as if you did. Are you sure you should be returning a pointer here? If the condition on line 45 evaluates to true, you must free ptr and q or you will leak memory. If the condition on line 50 evaluates to true, you must free ptr and q or you will leak memory.