Your First C Program

As a tribute in honor of Dennis Ritchie’s passing, I’d like to invite you to share your thoughts in this post’s comments about your first C program – either the code if you remember it approximately, or a story about when you wrote it.

Here’s mine.

I wrote my first C program in 1988 as a lab assignment for a fourth-year course in computer graphics at the University of Waterloo. In the first day or two of the course, our prof gave us our first assignment: Write a program that displays and controls a 3D animated robot with moving head, arms, and legs. Successive assignments would let us swoop around him, controlling point of view and zoom with a mouse, and other nifty features, but the first assignment was just to get him on-screen and capable of a little basic motion.

Oh, and the program was to be written:

  • to run on one of the lab’s four brand-new SGI IRIS workstations (oh, here’s the manual);
  • using a custom UofW internal library (oh, here’s the manual);
  • in C (we assume you know it, use man to learn this compiler’s command line switches if you need to);

and it’s due in a few days. I can’t remember exactly now, but I think we had something like five days. After all, this was just a warm-up initial exercise for the course.

Here’s the thing: I had never used C. Never even seen it.

Oh, I’d used many different languages in my undergrad career, from Cobol to Pascal to Prolog to 6809 assembler and many points between, but just never C. Don’t get the wrong impression, C was already used widely at UofW at the time and most of the other undergrads in the class knew it, but by some freak of course selection combined with professor allocation I somehow had managed to come across pretty much everything but C so far for the first three years.

Fortunately, there was K&R.

Armed with K&R and a printed-out C tutorial, I had a few days to learn a new language (huh? whaddayamean #include? oh, okay…), an unfamiliar compiler, an unfamiliar graphics library, and the quirks of this particular flavor of Unix – to produce a working program in an unfamiliar domain with unfamiliar concepts (graphics). And only that last bit was the actual topic material for the course. The language, compiler, library, etc. was just uninteresting scaffolding you were expected to know or just pick up on the fly, don’t bother the professor with questions about those when you can look it all up yourself.

I don’t remember what mark I got on the assignment, but the code worked.

I was glad that C was easy to learn, and that its manual in the form of K&R was so clear to read and understand. Thanks again, Dennis.

42 thoughts on “Your First C Program

  1. My first C program was in April 1991. My boss gave me a text file whose rows contained two filenames each.
    He wanted me to code an app to parse that input, look for the first filename in each pair and generate an output file named as the other member of the pair.
    All those files corresponded to .c or .h files but they had irregular indentation, bracketing and lacked of a formal “about” placeholder comment on top. That said, the output had to be a well formed .c or .h file with the heading placeholder comment as

    /*
    .
    Author:
    .
    */

    One additional request, as Gabriel (my boss) expected to use that filter in some future with single files, he wanted me to code two C apps: one that takes the source filename and the output one straight from the command line, and another C program that takes that text file containing pairs in each row and spawn() a transforming process as iterated thru rows.
    As I don’t remember which program I coded first, I mention both.

    Gabriel thought that I was an experienced C developer bcs I said so in the interview and he barely confirmed it in a few tests (I had “eaten” K&R 1st edition few days before the interview.

    I didn’t have much issues coding the app (syntax, standard library ok) but I fought a lot with the compiler. The compiler was too strict.

    If Gabriel is reading this I’d like to ask him whether he ever used my first app or was just to baptize me.

  2. I remember the excitement I experienced reading K&R’s book. It was love at first sight and even though I have moved up to C++ I remember fondly those days. In the last 30 years I have programmed in every language known to man, always looking for new adventures and semantic escapades. After having some affairs with Java and other languages, I realized that true love weighs more than fleeting lust and have stayed loyal to C and C++.

  3. My first program in C was small mod-file player (do you remember word ‘tracker’ from 90ths?).
    There was a variety of formats similar to midi files, but also carrying pcm-samples of music instruments at a specific pitch. I liked how they sounded and the way pretty complex compositions were crafted into a single file played through just a few channels (4 in early mod files). Given that that time in Russia it was very hard to get a decent audio card, everyone was building their own – mostly Covox-clones (in fact it was very simple R-2R DAC attached to the LPT port).
    So, being amazed with the music, I decided to write the program able to play it (I never cared that there were tons of them already :)). But Pascal language (along with Basic) was obviously a wrong choice. I also had some assembler knowledge coming from Atari with 6502 processor, but it looked way more complex on x86. And I picked C – strangely looking language with lots of braces and no ‘begin’/’end’ keywords :)
    The first version I wrote was very hard for the CPU to handle – each PCM-sample was calculated at interrupt and send to the port.
    Later I understood, that the most of the load comes from initialization of the calculation engine, so the version two calculated buffer of a kilo-sample or so and then interrupt handler just took a new value from the pre-calculated buffer. That worked so fast that a couple days after I implemented full TSR (Terminate & Stay Resident) version and was able to run some other programs (not many though – 640K of RAM, remember? :)).

    I still remember that feeling when I looked at the listing when program was complete – the code was so clean and neat that I had no idea, how could C was looking strange.

    P.S. and one more thing – I never coded ‘hello world’ in C before that mod player :)

  4. Looking back at more than 20 years as a software developer I must admit that I -never- wrote a ‘pure’ C-program. Started with Basic on Commodore 64 in the middle 80s, went through SmallTalk-hype in the 90s, switched to C++ and the #-family then. But, and I am amazed myself by that, I never wrote a ‘real’ C-program.

  5. I don’t remember the contents of my first C programs, but they were written while I was learning C in college at the Cooper Union in 1979. We were running an early release of UNIX on a PDP-11, and the C compiler was primitive. It didn’t support unsigned or floating point types, and it appeared to represent structure field names as simple offsets, because the same name could not be used for structure fields in different structures unless its offset was the same in both! Oh, and our terminals were from Olivetti, and featured scrolling rolls of paper, not video screens, an environment perfect for the “ed” text editor.

    I remember a year or two later the department acquired a VAX also running UNIX, and one could do ‘cat /dev/reader’ and hear the card reader in the next room activate and suck in the cards. (We had a few card punches that we would sometimes use to write programs if the terminals were all busy.)

  6. My first useful C program generated my first useful PostScript program!

    I was an engineering undergraduate in 1992 and had been introduced to
    Pascal a year or two earlier in my course. Prior to that, I’d grown
    up with Sinclair ZX Basic and hand-assembling Z80 machine language –
    now there’s some nostalgia for me, but I digress…

    I had a feeling that C would be useful in my future, so I decided a
    good project would be to neatly label all my cassette tapes. I bought
    the Plaguer/Brodie reference book (published by Microsoft, and about
    the only thing I’ve ever liked from that company!) and over the long
    summer break wrote – on paper – most of the code to take what I’d now
    call a line-oriented input file structure, and generate PostScript
    output. I think I might have borrowed the red and blue PostScript
    books from the library; I think I wrote the output routines later,
    once I’d had opportunity to compile the data structures and input
    routines.

    I still have the code, and a handful of input files. It’s a single
    file of about 400 lines of source, not counting 250 or so of
    Postscript (boilerplate and font handling, mainly).

    It would fit up to four labels onto each page of A4 (fewer if the
    contents lines were enough to require a folded label continuing on the
    inside), with folding lines to exactly fit standard cassette boxes,
    and handled an arbitrary number of input files, churning out pages
    until there was nothing more to process.

    The whole file is too big to post here, but I am still proud of
    managing comments like this on my first program:

    char *getline(FILE * const fp)
    {
    /* Returns one line of text (any length) from fp, stripping leading
    and trailing whitespace. Returned pointer is to a region of
    malloc’ed memory, and must be free’d after use.
    Returns NUll on failure, with errno set. */

    These days, I’d probably choose Perl or Python, and output in SVG, but
    it certainly was a good initial introduction to both C and PostScript.

  7. My wife still doesn’t get why there’s a copy of K&R in our poetry section.

    (first C was hello world on an Atari ST, 1987 or so)

  8. In 1987 or 1988, I had decided that it was time to “graduate” from GW-BASIC. I spent time in a University
    library reading through several books on programming languages, and C kept coming up. After sifting through
    many other choices, I finally decided to take the plunge.

    My first C program was almost certainly “Hello, World”, but the first “real” one I remember writing was a command-line MS-DOS utility. I’m afraid I can’t remember what it did, but I do remember that learning “structured programming” was tough: the notion of a function, if… then… else without line numbers, all these other things wasn’t so easy to get a handle on. I didn’t have K&R, or even know about it! I encountered it years later. Now, I’ve made a career of C and C++.

    It took time to appreciate the simplicity of C, but I’m sure glad that I took it. Thanks, Dennis!

  9. Well, after I sold a program in C, I figured I needed to learn the language. What fun, I can still remember 1987 with QuickC on a 286 PC… Every time I made a pointer error, a full reboot (about 2 minutes) and reload the compiler (another minute) make the change and compile (another 2 – 4 minutes). Wow, that was pain!

    But two months latter I had my own library of Direct to Video (mono and color) for pop ups and menus and check boxes, most of the then typical Text Based GUI’s. That was the easy part, I then needed to hook a 1 millisecond timer in to control digital IO, and a further backgroud task of an Interrupt driven serial port. Cutting edge stuff at the time.

    Rebooting the system just seemed like it was my life’s calling. But it shipped complete in three months, and it was even faster then I had every dreamed of …with the entire display, and digital IO updated avery millisecond, and recieving async serial, on two chanels and updating statistics.

    Thanks for the good times Dennis! (no really, I loved it!!)

  10. ‘C” was the second programming language I learnt after Pascal. While the first code to be written was – rather unsurprisingly – the ‘HelloWorld’, the real piece of code (well, at the time I thought it was a ‘real’ code) had to find out the largest number amongst a random series of numbers. The input process would continue till the user presses ‘N’ to a question ‘any more?’ (ah, that ampersand in scanf()!) and then the program would print out the largest number entered. Pretty ordinary compared many which are posted here, but the fact that I could reach an entry into an array with incrementing a pointer was a revelation. I felt for the first time, that I was actually treading in the memory locations of the machine! Amazing. Needless to say, KnR was beside me all through.

  11. My first C program was a program to measure the bandwidth/latency of a computer cluster using the MPI library, as part of a course in parallel computing. This was part of a computational science degree, so up until then I had only programmed in Matlab and Fortran. As for Herb, the lecturer assumed knowledge of C from the get go, so I bought K&R and got to work. This course was a real eye-opener for me, because it led me to install Linux for the first time (for easy access to gcc and ssh), and to learn Emacs.

    Here it is:
    #include
    #include
    #include
    #include
    /*Program for testing the bandwidth of a parallel system */
    int main(int argc, char **argv) {
    int rank;
    int j;
    int count;
    int tag=1;

    double start,finish;
    MPI_Status status;

    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);

    for(count=8;count<=8192;count=2*count){
    unsigned char msg[count];
    start=MPI_Wtime();
    for(j=0;j<100;j++){
    if (rank == 0)
    MPI_Send(&msg,count,MPI_UNSIGNED_CHAR,1,tag,MPI_COMM_WORLD);
    if (rank == 1)
    MPI_Recv(&msg,count,MPI_UNSIGNED_CHAR,0,tag,MPI_COMM_WORLD,&status);
    }
    finish=MPI_Wtime();
    if(rank==0){
    printf("Value for Ts: %e\n",(finish-start)/100);
    printf("Value for Beta: %e\n",(finish-start)/count);
    }
    }
    MPI_Finalize();
    }

  12. My first C programs was an attempt at implementing the 1980s arcade game “Tron”. The environment was a DOS port of GCC/G++ known as DJGPP, along with a game programming library called ALLEGRO. I got a pretty decent-looking light-cycle game working, but I couldn’t write a reasonably non-stupid AI.

  13. My first C programming was done on a Commodore Amiga in 1987. I already had read a lot about C, but since my professional career was as an IBM mainframe systems programmer, I had never had access to any UNIX machines, or C compilers till I got an Amiga. Wonderful memories of those great little machines!

    I had read and implemented much of Kernighan and Plauger’s “Software Tools” on the mainframe, and had absorbed much of K&P’s “Elements of Programming Style”, so reading the old Amiga ROM Kernel manuals and the Lattice C compiler manuals was not totally alien.

    My first C programming was of course “Hello World”. It was an achievement to get that compiled and running, because first I had to learn how to use make, and the command line, and the compiler flags, and do link edits.

    After Hello World, my first non-trivial C program was to print mandelbrots and julia sets in black and white on an old TRS DMP2100 dot matrix printer, at 180 DPI. It required a lot of bit fiddling to build the single print line (24 rows of dots) extending the length of the print line).

    However, I got it working, and was now ready for the real reason I bought a C compiler: Writing a printer driver for the DMP2100 printer so I could do things besides fractals pictures on my printer.

    It took me a couple of weeks of concentrated development to get it going and working, with support fo all of the Amiga OS print services features. By the time I was finished, I felt pretty comfortable with C, with unix style services, and the Amiga OS.

    I learned a lot getting those programs to work. I recall the hardest thing for me to understand was the lack of record orientation on unix type operating systems, completely different than the record oriented mainframe world.

  14. Before I get to my first C program, we need a bit of back story. I was graduated from college in May 1984 with a degree in Computer Science, which entailed learning Fortran, Cobol, PL/I and 370 Assembler. Due to some less-than-deligent job-hunting, I didn’t find a position until Jan 1985 (Hey — we didn’t have Monster.com back than. Looking for a job then meant sending resumes throught the “mail” in response to ads in a “newspaper”). In those months of unemployment, someone told me that what employers were really looking for was programmers who knew C. So, I bought a C tutorial (not K&R) at the local bookstore, and started to read it. However, since I didn’t have access to a C compiler (My TRS-80 only had a Basic intrepreter & Z-80 assembler), my education was more theortic than practical. When I finally landed a job, my first task there was to take the Z-8000 Assembler source code for the system embedded in the company’s new vending terminal, and document it.

    After producing a small book, I was told to use that doumentation to rewrite the system for the older vending terminal (in 8080 Assembler) to use the same structure as the new terminal. However, after 9 months of work on that, it was determined that just replacing the older (custom build) terminals with PCs would be cheaper.

    So, I was told to, again, take the documentation I had written, and create a similarly structured program for the PC — but instead of using assembler, like the previous version of the system, I was to use C. I was given a Xerox of a magazine article of C to learn how to write code in C. (I also dug out the book I had purchase a year & a half earlier, but I used that mostly as a reference rather than reading it completely — big mistake).

    First of all, beyond “printf”, I knew nothing of the standard library, and the concept of “malloc” was completely alien to me, even if I had known of the function. But, that wasn’t a problem, as I was porting (that term wasn’t used back than) an assembler program for an embedded system, and it had no standard library avaiable either. All memory allocation was done via hard allocated arrays and module static variables.

    Two years later, I was given the assignment to again rewrite the vending system for a PC — my second significant C program, but this time we were also completely rewriiting the server side for a new platform (and implementing 10 years of backlogged user feature requests) so it would have a completely new UI and many new features. By this time I was much better at C coding. The “funny” thing here is that, without realizing it, I had written it in a very OO style — The code I was manually writing probably looked much like the output from CFRONT with structs with function pointers and even some with a v-table. When a finally learned C++ about a year or so later, I kept thinking “Wow, this would have made (that application) easier!” (It would still be another five year before I got a job where someone paid me to write in C++) (I recent installed 5.25 floppy drive on my PC, and was going through some old floppies — I think I have the source to that….)

  15. In September of 1988 I was holding a copy of K&R’s The C Programming Language and tried to understand the first C program, the original Hello World. C looked alien to me.

    Fortran had been my first programming language in college. The school had a PDP-11 or some DEC machine that had been donated to the school by Digital Equipment, and we used it to compile our assignments. We had to schedule time in the lab, and that’s where I had my first experience in “concurrent programming.” The compiler (called the TKB, an acronym that I was never interested in knowing what it meant) was not multi-user, so every time you wanted to compile your program, you’d literally had to stand on your chair and yell “I’m going to use the TKB.” That would be the signal for other users to wait before submitting. Once the compiler was done you would “unlock” the TKB by yelling again and life was good…except when someone wanted to mess up your work and would submit the job simultaneously. There was no “event log” that would say who the offender was, so you would just curse and move on.

    Back to C. After college I had enrolled in a class and at the end we had to deliver an implementation of Tic Tac Toe. Having been an avid chess player during high school, I was excited to come up with the magic formula that would evaluate the position and perused through some books that had something on game theory and stumbled on what looked like a good algorithm for the game. The instructor had given us loose instructions on the user interface, but he preferred a GUI.

    Having no time and no money, only a copy of Turbo C, and not willing to invest time in a GUI that came in one of the C books from Herb Schildt due to several bugs I had to solve for it on another project, I decided to tackle the project using the algorithm, but alas, there was a problem position where the evaluation function would fail and the computer would lose. So I injected a “special case” to make sure that the function would safely make it should it encounter the losing position.

    At the end of the project, the other two teams got a beautiful user interface–and both teams used Pascal and not C–but my ugly baby with a command-line interface, writing O and X and asking for the coordinates of the next move, was the only one that would not lose.

    I did not get the best grade, though.

  16. My first main was written in august 1999.

    I had “played” with languages like Basic at home, or Pascal at University, but there, for my DEA (the last year of a Master degree in France, IIRC), I had to write code in C. Some post-graduate did try to teach us C, but I was at loss with those functions you could call putting parameters after and *before* the function name. I guess it was something like:

    p = (char *)malloc(25) ; /* what the **** ??? */

    It just escaped by understanding. I couldn’t “compile” that code in my brain, but coming from Basic and Pascal, I fell in love with C’s “for” statement. I knew this would be *my* language. So I worked for months with C, copy/pasting the code from one source to another in a large application (a neural network commanding a robot with a rotating camera). I knew some functions, but I failed to *understand* C.

    I even remember one student coming with a C++ book, with the “cout” instruction. “What is that for?” I asked, “we already have printf. What’s the point of yet another print function?”. His answer did not make sense at the time : “It can do operator overloading”. That guy was so right. I was so ignorant.

    So, in august, I knew I would try to work as a software engineer, but I had only a physics degree, with some related programming projects. And I knew I wasn’t able to code in C. I had read the K&R, but I couldn’t understand the chapter on pointers.

    So, I took the K&R I had bought weeks before, installed a “tutorial” version of Visual C++ 6 (the disc came with the book with a large blue C composed by “pluses” glued together, each program started with a messagebox warning) and, knowing the string functions were somehow lacking (it’s difficult to copy a string into another without having to care about the size of the destination), I decided I would learn by rewriting the string.h library.

    So, my first main was a list of what could be described as unit-tests of alternative functions prefixed by “r”.

    Starting with “rstrlen”, I had to learn pointer arithmetics, memory allocation, structures (my struct had a pointer to char, and a int for the size), and each and every rstr* function did reallocate the destination for the source to fit in it. I was so proud. To the contrary of my experience with Pascal and Basic, I felt the *power*.

    Since then, I got better and learned to love C++, bit by bit (what’s the point of putting functions inside structs?… private? what for?…), but strangely, this is where I disagree with B. Stroustrup : I believe, after months of sterile copy/pasting, those two weeks of intense C programming did give me strong basics on the C language, and thus, on the C subset of the C++ language.

    Dennis Ritchie (and others) contributed to make my life better. Not because I became a C software engineer, but because, unlike other languages, in which I felt “closed”, C impressed me, making me feel free. This is how I came to love programming, instead of just liking it.

  17. My first reasonable C program was adaptation of old console Star Trek game (sources here: http://almy.us/sst.html). I played Star Trek earlier on an IBM 360 clone in early 80-s (we have 2 console games on the machine) and then in 90s it was great to see the old friend on PC. That time I started working as a programmer and have worked on MFC project. Game was a little bit different and I changed it according to my experience, add some features and fixed some bugs. Then I played. Great! Thanks to Dennis for opportunity of sharing code throughout the world.

    P.S. At university we studied Pascal, but those cool guys who managed to get job wrote programs on C and were saying that “only C is real language”. They demonstrated printed on printer K&R like a bible (we have not this book in Russia then, in early 90-s). So since then and up to now I consider knowledge of C to be mandatory for every qualified programmer. I don’t know really why they choose Pascal to study programming.

  18. My first C program, written in 1985, was a renderer for a graphics protocol tailed to the needs of Schlumberger’s well logging business. It was probably the first non-assembly-language software to run on their PDP-11 based data acquisition systems. In college my preferred language was Pascal — the faculty hadn’t started teaching C yet. At that time, Pascal was very much a teaching language: elegant, superior to most of the alternatives, and crippled at building large systems. It was a delight to write C code.

    Software developers stand on the shoulders of giants like Dennis Ritchie. I mourn his passing and I celebrate his accomplishments.

  19. I wrote my first C program in 1992 after almost no programming experience. The program was supposed to optimize the targeting of the electron beam at Bates Linear Accelerator to produce a focused beam at the correct position on a target. Amazing that they let undergrads do things like that. It successfully controlled a series of focusing magnets but I left the summer job before that project ever had beam time. The “algorithm” used was pretty hideous. I still shudder to this day.

  20. My first C program (and my first program in any computer language) was to solve a quadratic equation using the standard formula after inputing the coefficients. I have always loved C and feel very sad about Ritchie’s passing away. And i am also eternally grateful to him.

    But I discovered his book after fully learning C. And I immediately understood what effective communication was. I am yet to see a book so well written. It is my ideal book.

  21. Lots of memories coming, it’s amazing how much things have evolved since then…
    Before starting C, I already had dropped out of university as the IBMpc had created so much demand for custom software. I was writing my stuff in Turbo Pascal, because it was so productive. But there were limitations and when Turbo C came out (87? 88?) the one thing that made me switch was the ability to store declarations in .h files, separately from the code in .c . This made it possible, for what I then called Units, to reference one another freely, and to me it was huge. So, if you ignore the toying around with samples, my first actual program in C was a port of my set of pascal libraries to C. It turned out to mainly be a tedious and boring affair as it really was a lot of “replace all BEGIN with {“. “replace all END with }”, etc :)
    Later, I did the same kind of switch, moving on to C++ (the old C++, the one without templates ;) ).
    But switching from Pascal to C was the most liberating one, everything felt “as simple as possible and not any simpler”, I still am very found of C-style constructs because of that.

  22. I wrote my first C program as a freshman. It was year 2001. in Croatia, Zagreb. I had a team that was willing to play DnD, and we copied the manuals, but couldn’t afford the dices. So I wrote a program that rolls a dice (any dice with two digits). But since I didn’t know any UI programming, we ran it in console. The numbers were too small, especially for us, since we drank along, So I used a file to load characters matrices (20 * 20, represented with hash and dollar sign). This is a smaller version sample:

    ###$#
    ##$$#
    #$#$#
    ###$#
    ###$#

    Those were the good times… Afterwards, we introduced a rule that anyone coming into my room must roll a “dvadesetka” (Croatian for d20), just for good luck and to mock my roommate, who was terrible DnD player.

  23. I cannot remember my first program, but I remember my first job back in 1989 and how I, just straight from school, where set to work in a group which had the responsibility for a big financial system written mostly in C. It was heaven on earth for one which just wanted to learn as much as possible, and my trusted companion all along was K&R. This code became my basis and reference point all along as I later moved on to C++ – and have stayed there since. But if I get the chance to program a bit in C it brings back good memories and reminds me about how much I enjoyed it.

  24. The first time I saw C code was in 1995, the first year of high school. We were taught Pascal in programming class, we used Turbo Pascal on DOS-like OS machines (Novell something), but on Unix machines we did not have a Pascal compiler, we had a Pascal to C translator there instead. I was curious about the C programming language and started experimenting to see what output the translator produced for different Pascal constructs. The code produced by the translator was horrible, but it was possible to figure out what it did. I don’t remember what exactly was the first program I wrote in C, it was probably one of the assignments.

  25. I wrote my first C program in 1997 at lab in my first year of CS education. I had a great teacher Kıvanç (couldnt remember his last name) and made me love C and C++ during his two years as a teacher and head of the CS faculty. I had programming experience with basic and very very little pascal before and first labs assignment is very easy for me so i decided to make something different and write a calculator. But didnt know the goto command in C i use in basic and ask my assistant how can i use it in C. He says we dont use gotos in C we use loops. After 2 hours i managed to write my first C program and my first while loop.

  26. Earliest C program that I remember writing was to print the Pascal’s triangle. I had written C programs before that but I have no recollection of what they were, though I know there were a very few of them only. Pascal’s triangle was probably one of my first 10 proper C programs and I remember it because we had a lot of fun with it and its variation.

    Because a lot of programs were part of the C course, many of my classmates had already learned them and memorized the programs. With Pascal’s triangle, we were able to suggest changes to the output pattern and see who will be able to modify their programs and come up with the desired output. It was a lot of fun.

  27. I didn’t get to have a proper introduction to C during my freshmen year in 1997 as the CS faculty decided that Java will be the new C/C++. I didn’t get to touch C much later when i took up a compiler writing course (first C progs were parsers) and without K&R’s book on C, i would never have understood C and might probably failed that course. I wonder, since Dennis’s passing, what sort of world would we be in if not for C?

  28. Well, i don’t have a story about a first C program, but your blog made me think of some of my students who are moaning most of the time, when they have to write more lines than “Hello World” would need. Why do they want to learn it then? I can hear the answer: “I’m forced to!” Here comes the reply: “No, you’re not!”. However, since reading the post about your first C program, my strategy of “Give them something more challenging” strengthened with every sentence. Thank you.

  29. My first C program would have been in my first year at college(1996). This would be Senior year at high school for those across the pond. My programming experience to then had been BASIC on my beloved Amstrad cpc 464. The first lesson required us to simply prompt for an input and display this value back on the screen. This would continue until the user had entered the value ‘q’, which would cause the program to exit.
    It was compiled and run on a Unix system.

  30. Hmmm, I think mine was a wrong-way ray-tracer; my school taught Pascal (about the same period as Herb) but I knew C was the hot thing in the industry. So, they both were a toy I was able to spend some leisure time on. I loved it, especially the ‘for’ loop, vs Pascal’s less flexible constructs.

  31. First semester was in Pascal [1994, Hebrew U. of Jerusalem, intro to CS course]. Second semester was in C [1995, data structures course, “we assume you know it”]. We had to program a sparse matrix library, implemented as two arrays: one for columns and one for rows, such that each entry in the array is the head of a linked list and the horizontal/vertical lists are “interwoven”:

    struct LinkedListNode_t {
    double data;
    LinkedListNode_t *next_in_row;
    LinkedListNode_t *next_in_col;
    };
    struct LinkedListNode_t **rows_arr;
    struct LinkedListNode_t **cols_arr;

    Through certain constraints I fail to remember, they arranged things such that some functions had to accepted LinkedListNode_t*** (pointer to a pointer to a pointer).

    Pointers and I weren’t friends before this assignment, to say the least :) But this assignment forced us to become friends, and we’ve been friends ever since. And of course it wouldn’t have worked without K&R.

  32. While I can no longer remember the first programs I wrote while learning C, would you accept a story about the first program I got to compile under my 8-bit CP/M C compiler in 1979?

    The program itself was a pretty bad Othello-playing program written by a grad student at the MIT Lab for Computer Science where I was employed as a Unix (version 7, on a PDP-11/70) administrator. It was while half-way through attempting to convert it into 8080 assembly language to run on my IMSAI 8080 that I decided to do something less mundane and write a C-subset compiler to COMPILE it into 8080 code instead ;-)

    So about 3.5 months into the project, I was able to begin compiling the program/debugging the compiler. Things were going pretty well, until I noticed that certain function calls were acting weird…some of the arguments being passed were never being received by the called function’s parameters. In fact, for any calls of two or more arguments, only one argument was ever being passed.

    I stared at this behavior for a while scratching my head…and then it hit me and my jaw dropped.

    Can anyone guess what I had done wrong?

    Well, one of the operators in C is the COMMA operator. While processing function arguments, I simply called my expression evaluator and then checked if the next token was a comma to know if there would be any additional arguments. As originally implemented, there NEVER WOULD be a second argument, because all the commas in the argument list were being processed as “the comma operator” !!

    I felt pretty stupid! Fortunately, it was an easy fix to take note of the fact I was processing a function argument list and “turn off” the usual meaning of the comma operator unless some parens were encountered…

    The other time I felt pretty stupid was when I misspelled “default:” as “defalut:” (so the compiler thought it was looking at a label rather than a switch construct) in my implementation of a low-level printf-related formatting function…which resulted in illegal % conversions not quite doing what they were supposed to do, lol. That one lasted into several months of production release!

    I had the pleasure of meeting Dennis once at the Boston Usenix conference around 1980, where Ed Ziemba and I had set up a demo of Ed’s MARC operating system (single-user single-process Unix clone that ran parasitically on CP/M-80 machines). I think that one of the high points of my life was giving a demo of a software project to Dennis Ritchie and seeing it bring a big smile to his face. It has definitely been a sad week.

  33. While not as impressive as many examples here I still remember it. My first C program was the cliché printf(“Hello World!\n”); in Borlad C++ 2.0 around 1991 on MS-DOS. I was about 11 years old at the time and his simple Hello World represented a shift from the world of gwbasic to an exciting world of more complex applications. Most importantly learning C benefited me immensely in my career as IT pro. Using C to write some system utilities to make my work more efficient, or just to understand windows/Linux internal data structures better to improve my diagnostic skills…

  34. The first C program I remember writing where on the Mac SE. I was trying to write an Infocom text adventure and was playing around with text interpreter logic. I think the compiler was called Mini C or Small C or something. It barely had any type checking and really was just a ever so slightly higher level macro assembler :-) Needless to say, coming from Turbo Pascal, I loved it.

    Ironically after a decade of .NET I know find myself writing C++ for work and Objective C for pleasure. What goes around comes around.

  35. My freshman year of college was ’88-89 – I guess nowadays you should say 1988-1989 (I am struggling to accept the fact that I’m old – and, Herb, if you were at Waterloo in 1988 then you’re old, too! ;)). My exposure thus far had been to BASIC and Pascal. My college was lucky enough to “expose” me to Ada (I’ll leave my college nameless for their protection) as well. I decided to take a “leap” and take a course as a freshman involving C. Boy, do I hate to sound like a nerd but I thought C was a really cool language. Void (pardon the pun) of all the “restrictions” of Pascal/Ada, I liked what I could do with it but more importantly it make me think about what was going on at the “machine level”. Yeah, it’s more productive to get “away” from machine/assembly language programming but I don’t think that until I truly understood what was going on “underneath” the compiler did I become a better programmer. So I owe that to C. That said, I moved on to C++ shortly after that and C++ is the “love of my life” as far as languages go but it all started with C, so for that, Dennis, I say “thank you!” I recall reading his book as an 18 year old freshman and having read literally hundreds of programming books since I must say it was very “readable” and helped me to understand C immensely. As Peter Norvig said in his “essay” on teaching yourself programming in 10,000 hours I agree that C/C++ are difficult to learn but once you do they provide the right balance between what’s going on down at the processor level and giving you the ability to abstract a lot of that away. Contrary to popular belief, I don’t think programming is easy, but thanks to Dennis he made it much easier. And I love his running joke, “C gives you the power of assembly language with the convenience of…assembly language.” Comedy! RIP

  36. So, recently I got an in-person interview with Fog Creek software, but somehow I had missed that C is the “lingua franca” (their actual words) of the Fog Creek interview process. So, with a week to go, I had Staples print me a copy of K&R along with the C language specification and got to work.

    Sadly, I did not manage to make it into Fog Creek, but even still, the knowledge was invaluable — I will likely never look at code quite the same.

Comments are closed.