My structure file only displays the last line of my fstream files. I also question abo

Pages: 12
post all your updated code
you need to fix at least three things:
- the format string in printf()
- increment the pointer in getWidgets()
- set the .number member for all your elements


> s_ptr++, NOT *s_ptr++. You incremented the value of what is stored at the
> memory location stored in the pointer.
actually, precedence rules will execute that as *(s_ptr++) giving «expression result unused» warning
the unneeded dereference is a conceptual error, but the should produce the expected result.

however, I do agree that it's confused and such construction should be avoided using parenthesis to clarify
*(s_ptr++) or (*s_ptr)++
(again, I do consider both wrong as no dereference is needed, and do wonder why OP reached such solution)

edit: an alternative to increment the pointer would be to use array notation: s_ptr[count].number


> In ShowWidgets, you need to move s_ptr++ to AFTER the "}". (move line 115 to line 117).
if the condition succeed, the pointer is incremented
if the condition fails, the loop is terminated
however, there's one caveat, s_ptr->number is not initialised for all the elements of the array (there is no constructor for Widget that sets it to 0)
Last edited on
Topic archived. No new replies allowed.
Pages: 12