Entry 1: i've been procrastinating...

A walk through three C problems that taught me how to stop worrying and love the segfault.

POV lol

I've been procrastinating. I've been meaning to start writing these almost a month ago but have just been rotting away since summer started (which was much needed tbh) but here it goes! The goal for this blog is to kinda document my progress as a dev and talk through my thought process as I learn new stuff in my CS classes at uni and just personal projects that I randomly pick up. end goal is to basically get better at this stuff by talking to myself and i guess putting it out there to see for anyone interested.

So here's how i'm forcing myself to get started: an assignment from my computer architecture class. We had to complete three programming problems in C, each testing a different concept: string parsing, sorting structs, and assignment-based data aggregation.

Let’s walk through them.

Problem 1 – Weighted Student Grades

We had to read weights from a file and calculate weighted averages for 20 students. Here's the basic idea:

while ((c = fgetc(file)) != '\t' && c != EOF) {
  name[i++] = c;
}
name[i] = 0;

This little loop reads the student’s name until it hits a tab character. Took me a while to realize how fragile tab-delimited parsing can be. One wrong keystroke in the input file and you're printing garbage.

Problem 2 – Sorting Students by GPA

Next we had to sort 100 students by GPA using qsort. This was surprisingly painless once I wrote the comparison function:

int compare(const void *a, const void *b) {
  const struct Student *x = a;
  const struct Student *y = b;
  return (y->gpa > x->gpa) - (y->gpa < x->gpa);
}

Yeah, I didn’t know you could do that either — that return line basically subtracts two boolean expressions to sort descending. Beautifully cursed.

Problem 3 – Class Statistics

The assignment codes (P, A, Z, etc.) could come in any order, and we had to track min, max, and average for each category. I learned really fast that mixing up indices would mess up everything.

printf("ASSIGNMENT: %s\n", fullName(codes[j]));
printf("MIN: %d\n", min);
printf("MAX: %d\n", max);
printf("AVG: %.1f\n\n", avg);

All that after storing grades in a 2D array and keeping careful track of totals across nested loops. Shoutout to whoever invented for-loops.

I'm slowly realizing that being a good software engineer isn't about knowing all the answers — it's about knowing how to debug your very wrong guesses. That was really corny actually mb.. i just mean like it takes a lot of trial and error cus this was a painstakingly long process

These three problems taught me (specifically in C cus it was such a weird change from Java or Python): Anyway. This is Entry 1. Hopefully not the last.
Back to procrastinating.

– Armaan
← back to weblog