Difference between revisions of "C header structure"

From ATI public wiki
Jump to: navigation, search
(Created page with "==sample.h== <source lang="c" collapse="false" first-line="2"> include guard - ei lase funktsioone üle defineerida: #ifndef SAMPLE_H #define SAMPLE_H /* Funktsiooni dek...")
 
 
(One intermediate revision by the same user not shown)
Line 32: Line 32:
 
}
 
}
 
</source>
 
</source>
 +
 +
Building
 +
 +
'''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