op counter
entirely. If retaining counter
as output parameter I wouldn't increment with every loop run, but simply assign the final value of i
to. Checking the result of calloc
is just as essential as checking the one of scanf
, you should add this hint, too.
@Aconcagua I will add the hint re calloc, although I disagree with being as essential. It's way easier to enter a non-digits than exhausting memory. I usually try to make minimal changes to ease understanding (in this case pass by value vs pointer). For instance, I would use for()
in convert as it fits naturally.
– user9706
Well, essential from programme safety point of view – maybe me having been to long into this sector ;) Indeed, bad user input occurs much more easily than memory allocation failing. On value vs pointer: You might yet add an introductory paragraph explaining the by-value aspect of parameters – clarifying why changing counter
to a pointer is necessary at all...
Add a comment