Sunday 21 September 2008

C programming

C programming


Not an ideal course

In August 1996, I started attending a C programming course at Kalamazoo in Northfield, a suburb of Birmingham, in which I learned to write simple programs using the C language. It wasn't an ideal course for me, being designed for people with little or no programming experience rather than for established programmers learning a new language. A lot of time was therefore taken up with fundamentals that other students needed to know but I didn't. Nevertheless, it was the only programming course available with government funding except for a COBOL course that I obviously didn't need to attend, especially as it was at a similiar level. I did all that was required to achieve a City and Guilds certificate, pictured right; click on it to enlarge.

I also helped the other students a lot. However, the basic course didn't keep me fully occupied so I used the spare time to do some little projects of my own. In this way, I learned a lot more about C than I otherwise would have done. None of these programs were part of the course syllabus. Indeed, I haven't kept any record of anything that was in the course syllabus, reflecting just how basic it was.

Numbers

My first program found all prime numbers in a given range. My second, a variation of the first, found prime factors for twenty numbers starting with a given number. These programs helped me to learn more about calculations and loop control than I could learn just by sticking to the course syllabus.

Colours

The third program was a colour guessing game, which really infuriated my tutor. He was obviously uncomfortable about teaching experienced programmers such as myself, and couldn't or wouldn't understand that this game provided the perfect training exercise for me. Sometimes known as "Bulls and cows" or "Hits and misses", it is possible that you've played this game using pen (or pencil) and paper. On paper, it is a game for two people. Before play begins, each player selects a combination of four colours (from six allowable choices) in which duplicates are allowed. Each player then takes turns to guess the other person's colour combination in the correct order. A colour in the correct position counts as a bull or hit, while a correct colour in the incorrect position counts as a cow or miss.

In my computer version, the computer takes the place of one player. There being only one player, I allow the option of solitary play, where the player simply tries to guess the computer's colour combination within a certain number of moves, or competitive play, where the player and the computer play against each other. In fact, once you get the strategy right, you can beat the computer at solitary play every time, but I set the limit on the lenient side to allow novices and less skilful players a reasonable chance. Those players who learn the best strategy should use it to compete against the computer, which I programmed to use that best strategy.

Although the tutor didn't like it, I actually learned a lot more about loop control and string and array manipulation, all of which would be essential in a commercial environment. The tutor indicated that the only way in which I could impress him was by doing a simple version of a small commercial system, but that would have involved file handling. As he only taught us about file handling at the very end of the course, there was no way I could have done a suite of such programs. In any case, it would have been less useful to me as a training exercise.

I assume that one reason for my tutor's discomfort was that he expected me to play endlessly with the game. Actually, I didn't play much, though I obviously needed to test it. Really, my satisfaction lay in getting it to work using C.

Gateshead

In fact, I originally wrote this program using COBOL in the seventies during my spare time. I incorporated it into a live system used by Gateshead social services, but there was nothing in the menu to direct anybody to the game. I occasionally played with it during gaps between work or at lunch times. Eventually, I showed it to the analyst responsible for the system, emphasising that there was no way for any user to play the game because it wasn't included on any menu. The analyst nevertheless told them anyway, with the result that the users amused themselves endlessly while that version of the software existed.

Gateshead metropolitan borough council would have upgraded to a different type of computer eventually, but by then I'd long since left to work elsewhere. I don't know if my little game was converted to work on the new system, though it would have been easy enough to do. Did it simply get dropped, to the disappointment of those who used it, or did they persuade somebody to incorporate the game into the replacement system? I suspect the former, though I'll never know. In any case, the system has probably been replaced several times given all the technological changes. Even if my program was upgraded once, I'd be very surprised if it survived all the changes.

Printing

Getting back to the 1996 course, I finally wrote a program to format off-line screen print to produce screen images on listing paper. I put this together hastily at the end of the course so that I could keep evidence from my first three programs, in case I wanted to show it to a potential employer, but no opportunity arose where it might have been relevant. Nevertheless, they proved useful when I learned Visual Basic and will also prove useful if I learn any other programming languages.

No comments: