stdio.h
ไฟล์ส่วนหัว stdio.h ย่อมาจาก Standard Input Output มีข้อมูลที่เกี่ยวข้องกับฟังก์ชันอินพุต/เอาต์พุต
นี่คือตารางที่แสดงฟังก์ชันบางอย่างใน stdio.h ในภาษา C
| ซีเนียร์ | ฟังก์ชัน &คำอธิบาย |
|---|---|
| 1 | printf() ใช้สำหรับพิมพ์สตริง จำนวนเต็ม อักขระ ฯลฯ บนหน้าจอเอาต์พุต |
| 2 | scanf() มันอ่านอักขระ สตริง จำนวนเต็ม ฯลฯ จากแป้นพิมพ์ |
| 3 | getc() มันอ่านตัวอักษรจากไฟล์. |
| 4 | putc() มันเขียนอักขระลงในไฟล์ |
| 5 | fopen() มันเปิดไฟล์และฟังก์ชั่นการจัดการไฟล์ทั้งหมดถูกกำหนดไว้ในไฟล์ส่วนหัว stdio.h |
| 6 | fclose() มันปิดไฟล์ที่เปิดอยู่ |
| 7 | ลบ() มันลบไฟล์. |
| 8 | fflush() มันล้างไฟล์. |
นี่คือตัวอย่าง stdio.h ในภาษา C
ตัวอย่าง
#include<stdio.h>
int main () {
char val;
printf("Enter the character: \n");
val = getc(stdin);
printf("Character entered: ");
putc(val, stdout);
return(0);
} ผลลัพธ์
นี่คือผลลัพธ์
Enter the character: s Character entered: s
stdlib.h
ไฟล์ส่วนหัว stdlib.h ย่อมาจาก Standard Library มีข้อมูลฟังก์ชันการจัดสรร/เพิ่มหน่วยความจำ
นี่คือตารางที่แสดงฟังก์ชันบางอย่างใน stdlib.h ในภาษา C
| ซีเนียร์ | ฟังก์ชัน &คำอธิบาย |
|---|---|
| 1 | malloc() มันจัดสรรหน่วยความจำระหว่างการทำงานของโปรแกรม |
| 2 | ฟรี() มันทำให้หน่วยความจำที่จัดสรรให้ว่าง |
| 3 | ยกเลิก() มันยุติโปรแกรม C |
| 4 | ออก() มันยุติโปรแกรมและไม่คืนค่าใด ๆ |
| 5 | atol() มันแปลงสตริงเป็น int แบบยาว |
| 6 | อะทอลล์() มันแปลงสตริงเป็น int แบบยาว |
| 7 | atof() มันแปลงสตริงเป็นค่าทศนิยม |
| 8 | แรนด์() ส่งคืนค่าจำนวนเต็มสุ่ม |
นี่คือตัวอย่าง stdlib.h ในภาษา C
ตัวอย่าง
#include <stdio.h>
#include<stdlib.h>
int main() {
char str1[20] = "53875";
char str2[20] = "367587938";
char str3[20] = "53875.8843";
long int a = atol(str1);
printf("String to long int : %d\n", a);
long long int b = atoll(str2);
printf("String to long long int : %d\n", b);
double c = atof(str3);
printf("String to long int : %f\n", c);
printf("The first random value : %d\n", rand());
printf("The second random value : %d", rand());
return 0;
} ผลลัพธ์
นี่คือผลลัพธ์
String to long int : 53875 String to long long int : 367587938 String to long int : 53875.884300 The first random value : 1804289383 The second random value : 846930886