Page 1 of 1
C and its simpleton I/O functions
Posted: Tue Mar 28, 2006 1:48 am
by bubach
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
Re:printing integers to screen without using an array
Posted: Tue Mar 28, 2006 1:54 am
by Solar
bubach wrote:
This school project led me to the conclusion that most C functions suck...
About half of the standard functions are sub-par, I agree with that.
...and you can't even clear the screen in a standard way.. ;D
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?

Re:printing integers to screen without using an array
Posted: Tue Mar 28, 2006 4:32 am
by bubach
Solar wrote:After all, how would you define "screen" in a portable way?

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.
Re:printing integers to screen without using an array
Posted: Tue Mar 28, 2006 5:03 am
by Solar
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.
Re:printing integers to screen without using an array
Posted: Tue Mar 28, 2006 5:32 am
by bubach
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.
Re:printing integers to screen without using an array
Posted: Tue Mar 28, 2006 5:50 am
by Solar
bubach wrote:
You can change position inside a file, right? So why not on the screen, if it's treated like a file?
It is not treated like a file. Because you cannot position on it.
Doing for-loops with printf("\b"); gets ugly pretty fast..
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.
Anyway, this is pretty pointless and very OT.
Pointless - I don't think so.

And the OT thing can be helped.

Re:C and its simpleton I/O functions
Posted: Tue Mar 28, 2006 10:34 pm
by zloba
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.
Re:C and its simpleton I/O functions
Posted: Mon Apr 03, 2006 7:38 am
by Pype.Clicker
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.