2 ms·
fscanf (STDIN, "%d", &a); the program goes beserk as soon as the first non-number is read out of standard input. in both cases, you need error checking (which
by PaulDavisThe1st 2y ago
fscanf (STDIN, "%d", &a);
the program goes beserk as soon as the first non-number is read out of standard input.
in both cases, you need error checking (which you "know about").
- unwind 2y agoNo actual C programmer who has been around the block more than halfway should do that. The mantra is: "read into a character buffer, then parse that". It's more code, sure, but it buys you a lot of good things. I/O is hard.
- PaulDavisThe1st 2y agoNo C++ programmer who has been around the block more than halfway should do cin >> a; and assume that it works. But also ... sscanf (the_buffer, "%d", &a); doesn't help the problem in any substantive way.