I did manage to avoid scanf() in a tiny mastermind game for school.. I prefered using getch(); so that I would be sure that the user didn't type anything else then five unique numbers..
This school project led me to the conclusion that most C functions suck, and you can't even clear the screen in a standard way.. ;D
C and its simpleton I/O functions
Re:printing integers to screen without using an array
About half of the standard functions are sub-par, I agree with that.bubach wrote: This school project led me to the conclusion that most C functions suck...
The eternal struggle between the concepts of language vs. library. Don't compare C (which has a real bare-bones library) with Perl / CPAN or Java. I think C/C++ did it the right way when they left all "fancy" stuff to third-party libraries. After all, how would you define "screen" in a portable way?...and you can't even clear the screen in a standard way.. ;D
Every good solution is obvious once you've found it.
Re:printing integers to screen without using an array
If you can write to the screen you should be able to do other things with it too, like clearing it or changing cursor position.Solar wrote:After all, how would you define "screen" in a portable way?
Re:printing integers to screen without using an array
Standard C doesn't know about "screens". You cannot write to a "screen" with standard C, so it's natural you cannot clear it or change cursor position. The textual I/O primitive of standard C is the line - which might be in a file or via some other, potentially interactive device.
Everything beyond that is up to some external library. It might be portable or making full use of a specific platform. It might be geared for security, or efficiency, or good looks. It might be proprietary and coming with professional support, or it might be GPL.
This allows you to take your pick, instead of being shackled to how the language designers thought things ought to be done. I still consider this the biggest "pro" of C/C++, as opposed to e.g. Java.
Everything beyond that is up to some external library. It might be portable or making full use of a specific platform. It might be geared for security, or efficiency, or good looks. It might be proprietary and coming with professional support, or it might be GPL.
This allows you to take your pick, instead of being shackled to how the language designers thought things ought to be done. I still consider this the biggest "pro" of C/C++, as opposed to e.g. Java.
Every good solution is obvious once you've found it.
Re:printing integers to screen without using an array
You can change position inside a file, right? So why not on the screen, if it's treated like a file? Doing for-loops with printf("\b"); gets ugly pretty fast..
Anyway, this is pretty pointless and very OT.
Anyway, this is pretty pointless and very OT.
Re:printing integers to screen without using an array
It is not treated like a file. Because you cannot position on it.bubach wrote: You can change position inside a file, right? So why not on the screen, if it's treated like a file?
Yes, because it's using the wrong tool for the right thing. Take (or write) a library that does the extended terminal stuff. You don't do for-loops of putchar() for printing lines, either.Doing for-loops with printf("\b"); gets ugly pretty fast..
Pointless - I don't think so. And the OT thing can be helped.Anyway, this is pretty pointless and very OT.
Every good solution is obvious once you've found it.
Re:C and its simpleton I/O functions
if you're on windows, you can use Console API.
on Unix, you can try Ncurses (which is a wrapper on top of a complete anarchy of terminal standards and their escape sequences, and the lack of an API).
i think there ought to be some general (cross-platform) standard for a Console API, but not as part of any language standard.
on Unix, you can try Ncurses (which is a wrapper on top of a complete anarchy of terminal standards and their escape sequences, and the lack of an API).
i think there ought to be some general (cross-platform) standard for a Console API, but not as part of any language standard.
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:C and its simpleton I/O functions
iirc, there should be ANSI escape codes for clearing, changing colors and position. They are (afaik) supported on Unix terminals, DOS command lines (with the proper ANSI.SYS driver) and probably windows aswel.