C中的头文件“ stdio.h”和“ stdlib.h”

标准版

头文件stdio.h代表标准输入输出。它具有与输入/输出功能有关的信息。

下表显示了用C语言显示的stdio.h中的一些功能,

序号功能与说明
1个printf()
用于在输出屏幕上打印字符串,整数,字符等。
2scanf()
从键盘读取字符,字符串,整数等。
3getc()
从文件中读取字符。
4putc()
将该字符写入文件。
5fopen()
打开文件,所有文件处理功能都在stdio.h头文件中定义。
6fclose()
关闭打开的文件。
7remove()
删除文件。
8fflush()
刷新文件。

这是C语言中的stdio.h的示例,

示例

#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代表标准库。它具有内存分配/释放功能的信息。

下表显示了用C语言显示的stdlib.h中的某些功能,

序号功能与说明
1个malloc()
在程序执行期间分配内存。
2free()
释放分配的内存。
3abort()
终止C程序。
4exit()
终止程序,不返回任何值。
5atol()
将字符串转换为long int。
6atoll()
它将字符串转换为long long int。
7atof()
将字符串转换为浮点值。
8rand()
返回一个随机整数值

这是C语言中的stdlib.h的示例,

示例

#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