Difference between revisions of "C header structure"

From ATI public wiki
Jump to: navigation, search
 
Line 35: Line 35:
 
Building
 
Building
  
'''gcc mainc. sample.c -o sample'''
+
'''gcc main.c sample.c -o sample'''

Latest revision as of 08:27, 16 December 2014

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 main.c sample.c -o sample