C header structure

From ATI public wiki
Revision as of 08:06, 16 December 2014 by Hkinks (Talk)

Jump to: navigation, search

sample.h

/* include guard - ei lase funktsioone üle defineerida*/
#ifndef SAMPLE_H 
#define SAMPLE_H

/* Funktsiooni deklaratsioon */
int sample(int a);

#endif

sample.c

#include "sample.h"

int sample(int a) {
  /* Funktsiooni definitsioon */
  return a * a;
}

main.c

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

int main(void) {
  int a = sample(4);
  printf("%d\n", a);
  return 0;
}

Building

gcc mainc. sample.c -o sample