r/learnprogramming • • 3d ago

C programming language learning guide

Where can i learn C from basic ?

10 Upvotes

31 comments sorted by

View all comments

Show parent comment

2

u/lisnter 2d ago

K&R is a good way to go. I read it 40 years ago and learned enough to start my summer job. The book isn't very long so you can read it in a few days. It's best if you have a simple project in mind so you have something to apply the concepts to; but keep it simple to avoid overwhelming yourself with every detail.

These days a lot of the complexity is just setting up the environment properly though for vanilla C, Visual Studio Code gets it done painlessly (or good-old gcc).

2

u/twr14152 2d ago edited 2d ago

You really read that in a couple of days? That was a month of agony for me. Had to dedicated one hour every morning for it. Couldn't take any more of it than one hour. And i had to restart at least once. It was hard as hell to stay focused on it. There was good material in there for sure but the logic in the example were so recursive i had to bend myself into a pretzel to eek out understanding. The partial code snippets and referencing of earlier functions in the examples were exhausting. Other than that i did get through it, and have the scars to show for it. When i hear people breezing through it, it really makes me question my intellectual choices in life.

2

u/Ratfus 2d ago

Could someone read that in a few days? Sure. Read and understand it, absolutely not; unless, you were already extremely knowledgeable about programming and C.

2

u/lisnter 2d ago

I had taught myself BASIC and Pascal in High School and understood the concepts of control flow, variables, arrays, etc. so I just needed C syntax to get started. Keep in mind, this was ~1985 so pretty much all one had to work with was libc, a text editor (epsilon/emacs clone) and make; I didn't need to know much to get started. Also, the programming team was very small (3) and very inexperienced so my lack of extensive C experience was not really out of place.

I read half/third of the book over a weekend before I started the job, learned while doing and read the rest of K&R over about a week. We were also not building an Amazon pre-cursor - it was a relatively simple Gantt chart project management tool for a compay that wanted to branch out into commercial software. Again, in 1985 it didn't take much.

This was my summer job so I left in September but the CFO was a neighbor and friend of my parents who got me the job - he said, "Hey lisnter, you know C right?" - and the project was cancelled soon after I left. This company didn't have any business trying to branch out - they did a post-production for Hollywood movies - but the experience was way more than other college students my age which was critical to get additional real programming jobs the rest of my undergrad career.

The coolest contribution I made to that project was a nearly instantaneous screen-update function. Back then, there were two main ways to write to the screen (80x25 text only): printf() and an interrupt. Both of which were horribly slow. Fortunately, I was an avid reader of Byte magazine and had just learned about the memory map of the IBM PC. In these early days, everything was far simpler - some would say dangerously so - and you could write anywhere in memory you wanted if you had a pointer to it. All I had to do was define a pointer and initialize if with the right value; something like:

int *videoMem = 0xa0000 ; // start of IBMPC video memory

and I would de-reference videoMem to write the value:

*videoMem = ( int )'A' ;

++videoMem ;

This ran extremely fast and could update the screen practically instantaneously. The business logic would hand me an 80x25 array (only 2000 elements) with the right values already loaded and I'd just pump it out to the screen. Since this was text-only it could use the special IBM PC line-art codes (above 0x7f) to make some convincing boxes and charts.

Fun days.

3

u/twr14152 2d ago

Cool man. Thanks for sharing that. That was a unique time.

1

u/Ratfus 2d ago

Setting up the environment is a perfect task for chat gpt. A lot of home brewing commands that I'm not too fond of memorizing, and will only ever use for setting up applications.

Things that took me a few hours, could have easily taken 20+ without it. Had a brutal time trying to set up vs code, to program an atiny in assembly.

1

u/UpbeatYear3926 2d ago

40 years ago wow