DEV Community

Marcel
Marcel

Posted on

# Why I’m Embracing 21 Segfaults a Day at 17

Today, I hit 21 segmentation faults in C.

Good day guys, my name is Marcel and I’m 17, living in Nigeria, and getting ready to study Computer Engineering at FUTO. I already have some experience with JavaScript and building SaaS apps (I actually spent part of my afternoon fixing a caching layout for my web app), but I’ve spent the last month diving deep into C.

And honestly? C is kicking my teeth in. But I love it.

Coming from JavaScript, memory is an abstract concept. You create an object, and the engine manages the hardware for you. In C, you are the manager. I am building a simple contact book project to handle creating a contact, saving it on a dedicated .txt file which gets loaded when users want to view their contact list and it also handles functions such as searching and deleting a contact. Today I was working on the header file that adds a contact and was having trouble allocating memory to store the user names e.g, (like my legal name, Izuoba Somtochukwu Marcel). Managing malloc and character buffers using raw loops felt like trying to defuse a bomb. One wrong index, and boom—Segmentation Fault.

Wrestling with the Input Buffer

Here is the exact single-user character loop I was battling today. I wanted to use %c so it would capture full names with spaces instead of cutting off like %s does, but I kept running into bugs where the loop would capture the leftover Enter key (\n) from previous inputs or loop infinitely:

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

typedef struct {
    char name[100]; 
    char phone[12];
    char email[50]; 
} contact;

int addContact(void) {
    contact add_psn;
    char *c = malloc(100 * sizeof(char));
    if (c == NULL) return 1;

    // Clearing the invisible newline character stuck in the buffer
    char garbage;
    scanf("%c", &garbage);

    printf("Enter Name: ");
    int i;
    for (i = 0; i < 99; i++) {
        scanf("%c", &c[i]);

        // Break instantly when the user hits Enter so it doesn't hang!
        if (c[i] == '\n') {
            break;
        }
    }
    c[i] = '\0'; // Manually sealing the string

    for (int j = 0; j <= i; j++) {
        add_psn.name[j] = c[j]; 
    }

    printf("Saved Name: %s\n", add_psn.name);
    free(c);
    return 0;
}
Enter fullscreen mode Exit fullscreen mode

The Shift From Code to Math

Later in the day, while studying finite mathematical induction, something clicked. In math, you prove a base case $P(1)$, assume $P(k)$ is true, and prove $P(k+1)$. When you write a loop like the one above—moving character-by-character through an input buffer—your brain is executing that exact inductive logic in physical hardware memory lanes.

Instead of waiting until I have physical ARM microcontrollers or hardware chips, I’m getting a head start entirely via software. I spent yesterday setting up PCB design simulation tools to practice building and routing boards right on my laptop. By writing my loops manually, handling the invisible newline characters trapped in the stream, and mastering pointers, I am learning exactly how software speaks to silicon before I ever print a physical board.

The Big Goal

People ask me why I’m bothering with raw C and low-level pointer arithmetic when I could just stick to high-level web frameworks.

The answer is simple: I want to help build a world-class automotive future for Africa. I’m actually a huge fan of Mercedes-Benz and hope to work with their engineering teams one day. But to build the smart, electric, and autonomous vehicles of the future, Africa cannot just rely entirely on imported Western or Asian chips. We need to develop our own domestic silicon architectures leveraging ARM instruction sets and high-performance functional cores like those of AMD.

To build a chip, you have to understand how code touches transistors. And to touch transistors, you have to survive the segmentation faults of C.

21 crashes today means 21 lessons learned. Tomorrow, we go again.

c, #beginners, #programming, #hardware.

Top comments (0)