Learning C

Earlier today I was reading an older book about microcomputers and how the only languages available at the time were FORTRAN, Basic, and Assembly. The book was published in 1977, so I wondered if C was available at the time. Turns out it was, but while I was on the Wikipedia page about C, I noticed that it’s currently ranked #1 on the TIOBE index. I’ve wanted to learn C for a long time, so I thought hey, why not just learn it?

Resources

I’m using this tutorial, GCC on Linux, and Code by Elementary.

Log

4:15 PM – I’ve done stuff in a bunch of other programming languages, but not really in C. I think a long time ago I made a Hello World program, but that was it. I know C has some features I’m not used to, like memory access, pointers, and strict typing. I’m going to see how much C I can learn in one evening. I might also continue tomorrow if I’m having fun. I’m so hyped to start! 😀

8:21 PM – So I’ve spent about 3 hours and I’m almost done with the tutorial. I made a number guessing game:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdbool.h> 

int randRange(int l, int h) {
    return rand() % (h-l+1)+l;
}

int main() {
    srand(time(0));
    int target=randRange(0,100);
    int guess;
    int guessCount=0;
    printf("I've picked a number between 0 and 100.\n");
    while ( guess != target ) {
        printf("What's your guess? : ");
        scanf("%d",&guess);
        if ( guess > target ) {
            printf("Too high.\n");
        } else if ( guess < target ) {
            printf("Too low.\n");
        }
        guessCount++;
    }
    printf("Correct! The answer was %d. You guessed it in %d guess%s.\n",target,guessCount, (guessCount>1) ? "es": "" );
    return 0;
}

I’ve only just started on the really cool stuff like pointers and memory access. I’m having fun and definitely want to continue tomorrow. See you then!

Leave a comment

Your email address will not be published. Required fields are marked *

Your data is processed in accordance with my privacy policy. Comments are manually approved and may take a while to appear.