C Index

C - Basic

Multiple Sources

To organize code in multiple files split above example in main.c, hello.c and hello.h. Content of main.c;

	#include "hello.h"

	int main() {
	    hello("world");
	    return 0;
	}
	

Header file contains declaration of the function hello, content of hello.h;

	void hello(const char* name);
	

Implementation of hello function in hello.c;

	#include <stdio.h>
	#include "hello.h"

	void hello(const char* name) {
	    printf("Hello, %s!\n", name);
	}
	

Compile;

	$ gcc -Wall main.c hello.c -o hello
	
C Index

This is part of the Tribu System Documentation. Copyright (C) 2020 Tribu Team. See the file Gnu Free Documentation License for copying conditions.