confusion.

an atypical computer scientist's blog

Work from the past: Scanflib

without comments

When I started studying Computer Sciences and Communication Systems, one of my first courses was an introduction to ANSI-C. To be honest, C is not the easiest language to learn. You have to care a lot about problems which are not even known in typical hobbyists languages of choice. You have to care about memory management, pointers, boundary checks and a lot more which is typically cared for by the compiler, interpreter or virtual machine for most newer languages like Java, the .NET languages or interpreted ones like Python or PHP.

However, on the other hand, C is a great language to learn what’s programming about and to get a deep knowledge and feeling for what a more complex platform might do when you call a “simple looking” function and you are wondering on the impact it has. As a language C is “high” enough to spare you from the pains of assembler and “low” enough to not bedazzle you with shiny functions you actually cannot find out for how they do their magic.

Back to the “historical” part, for me the greatest pain working with ANSI-C was to do user inputs. I always ran into problems when I wanted to read characters, interpret input as an integer or even as a double! So, when my knowledge was good enough, I started developing a pretty small but useful library to ease user inputs – and from the first version on I used it in a lot of projects and, as far as I know, it was in use by several further classes, too. Some days ago I did a little project in C and – although I didn’t use it (I had no user input) – I remembered my little library and so I wanted to post it here. Don’t expect too much, it does no magic and it was one of my first works in C ;)

Basically it provides only four simple functions to be used for reading multiple characters (up to 4096), a single character, an integer or a double value:

    int     readCharacters(char*	buffer, int chars);
    int     readCharacter( char*	buffer);
    int     readInteger(   int*		value);
    int     readDouble(    double*	value);

The library comes with a short example application (with comments in german ;) ). As usual, the short library is provided “as is” under the MIT license here for download.

Written by hwick

Oktober 30th, 2011 at 8:54 pm

Posted in Allgemein

Leave a Reply

*