What I meant was that you shouldand make getnum() return NULL when EOF was returned by any read functionCode:while (( number1 = getnum(infile, base)) != NULL)
With other words : Forget feof().
Kurt
What I meant was that you shouldand make getnum() return NULL when EOF was returned by any read functionCode:while (( number1 = getnum(infile, base)) != NULL)
With other words : Forget feof().
Kurt
And yet it's obviously a memory leak. Where do you free the previous result? Where do you free number_next before getting the next number? What do you think happens to that memory?
You're either not using Valgrind properly (e.g., static linking?) or it's missing this one for some other reason.
The moral of the story is that you still have to use your brain in addition to other tools.
The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss
After doing what You advised - I get a segfault
Here is the change (rest the same as on the previous page), only changed second while loop in main.
Shortened summary from valgrind -v:Code:while (((number_next = getnum(infile, base)) != NULL) ) { result = add(result, number_next, base); free(result); free(number_next); if (feof(infile) != 0) break; }
On an external server, didn;t want to put so many text here.
Ideone.com | Online C Compiler & Debugging Tool
Thanks in advance!
You cannot free result in that loop. It's still needed in the next iteration
KurtCode:while (((number_next = getnum(infile, base)) != NULL) ) { result = add(result, number_next, base); free(result); free(number_next); if (feof(infile) != 0) break; }