CodeBlanks Logo Icon CodeBlanks

Module design

  • C course
  • Intermediate
  • Lesson 13/116
  • 6 min

Design the skeleton of the helper library module.

Project: Helper library

In this five-lesson project you'll build a helper library. Each lesson adds a piece; by the final lesson you'll have a program that calls every helper.

You'll use what you learned in earlier groups: pointers, dynamic memory and string handling. Throughout the project you'll define six helper functions: str_len, str_is_empty, num_abs, num_sign, arr_max and arr_sum. In this first lesson you'll lay out the module skeleton: header declarations and main.

Header file structure

A header file holds function declarations (prototypes). A declaration is the function signature terminated with a semicolon: int str_len(const char *s);.

Here const char *s says the parameter won't be modified. You can write several declarations one after another; each ends with a semicolon. Declarations tell the compiler the function exists; definitions may live in another file. This split enables modularity in large projects.

Practice Write the module skeleton

Add prototype declarations for the six helpers: int str_len(const char *s);, int str_is_empty(const char *s);, int num_abs(int n);, int num_sign(int n);, int arr_max(int *a, int n);, int arr_sum(int *a, int n);. Write int main(void) and inside it print "Modül hazır" with printf.

Starter code

main.c
#include <stdio.h>

// helpers.h bildirimleri:
// str_len, str_is_empty, num_abs, num_sign, arr_max, arr_sum

// main: "Modül hazır" yazdır

Sample solution

main.c
#include <stdio.h>

int str_len(const char *s);
int str_is_empty(const char *s);
int num_abs(int n);
int num_sign(int n);
int arr_max(int *a, int n);
int arr_sum(int *a, int n);

int main(void) {
    printf("Modül hazır\n");
    return 0;
}

Expected output

Modül hazır

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Where are function declarations kept in C?

  • In a .txt plain file
  • In a .c source file
  • In a .o object file
  • In a .h header file Correct answer

Explanation: Declarations go in .h headers; definitions in .c sources.

2 Complete the str_len prototype

Question
int str_len(const char ____);
Answer
int str_len(const char *s);

Explanation: const char *s is a pointer to an immutable string.

3 Match helpers to purpose

Term Meaning
str_len String length
num_abs Absolute value
arr_max Largest element
arr_sum Array sum

All lessons in Intermediate