Skip to content
Discussion options

You must be logged in to vote

For a small C project, I’d start with one .c file if the project is genuinely tiny, but I’d introduce .h and separate .c files as soon as you have distinct responsibilities.

For example:

project/
├── src/
│   ├── main.c
│   ├── calculator.c
│   └── utils.c
├── include/
│   ├── calculator.h
│   └── utils.h
└── Makefile

The .h files contain declarations, types, and function prototypes, while the .c files contain the implementations.

For example:

// calculator.h
#ifndef CALCULATOR_H
#define CALCULATOR_H

int add(int a, int b);

#endif
// calculator.c
#include "calculator.h"

int add(int a, int b) {
    return a + b;
}

Then main.c can simply include the header and use the function.

I wouldn'…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by momoamr28
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug GitHub or a GitHub feature is not working as intended Programming Help Discussions around programming languages, open source and software development source:ui Discussions created via Community GitHub templates
2 participants