Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Lập Trình C

Viết file header riêng trong C

Các bước tạo header file:

  1. Viết code, lưu thành sub.h
  2. Chương trình chính subtraction.c include "sub.h" (dùng ngoặc kép)
  3. Hai file cùng thư mục

sub.h

int sub(int m, int n) {
    return m - n;
}

subtraction.c

#include <stdio.h>
#include "sub.h"
int main() {
    int a=7, b=6, res;
    res = sub(a, b);
    printf("Hieu: %d", res);
    return 0;
}

Kết quả

Hieu: 1