C语言的I/O函数介绍
C语言的输入输出函数定义在stdio.h里。本文主要介绍scanf / printf / gets / puts / fopen / fgets / fputs 这几个函数的用法。
一. 标准输入/输出
1.scanf() 与 printf()
函数原型及说明:
int scanf(const char *format, ...);
//scanf() 函数从标准输入设备stdin读取数据,返回与格式化字符串format成功匹配的个数。
int printf(const char *format, ...);<pre name="code" class="cpp">//scanf()函数将指定的字符串输出到标准输出设备stdout,如果成功,则返回输出的字符数(不包括字符串结束标识'\0'),否则,返回一个负数。
用法举例:
程序片:
char* input = malloc(32*sizeof(char));
scanf("%s",input);
printf("%s",input);
free(input);
输入与输出:
[liuyz@localhost Desktop]$ gcc -std=c99 -o StdInOut