Header Files ใน C มีฟังก์ชันไลบรารีมาตรฐาน ใช้ #include นำเข้า
Header Files สำคัญ
| Header | คำอธิบาย |
|---|---|
<stdio.h> | Input/Output Functions (printf, scanf, fopen, ฯลฯ) |
<conio.h> | Console I/O (getch, clrscr - Non-standard, Windows Only) |
<stdlib.h> | General Utilities (malloc, free, exit, atoi, rand, ฯลฯ) |
<math.h> | Mathematical Functions (sin, cos, sqrt, pow, ฯลฯ) |
<string.h> | String Functions (strcpy, strlen, strcmp, ฯลฯ) |
<ctype.h> | Character Handling (isalpha, isdigit, toupper, ฯลฯ) |
<time.h> | Date/Time Functions (time, ctime, localtime, ฯลฯ) |
<float.h> | Float Type Limits (FLT_MAX, DBL_EPSILON, ฯลฯ) |
<limits.h> | Integer Type Limits (INT_MAX, CHAR_BIT, ฯลฯ) |
<wctype.h> | Wide Character Classification |
ตัวอย่างการใช้งานหลาย Header
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main() {
char s1[20] = "53875";
char s2[10] = "Hello";
char s3[10] = "World";
int res = pow(8, 4);
printf("Using math.h, The value is : %d\n", res);
long int a = atol(s1);
printf("Using stdlib.h, string to long int : %ld\n", a);
strcpy(s2, s3);
printf("Using string.h, strings s2 and s3 : %s\t%s\n", s2, s3);
return 0;
}
ผลลัพธ์
Using math.h, The value is : 4096
Using stdlib.h, string to long int : 53875
Using string.h, the strings s2 and s3 : World World