一.只用于标准输入(stdin)和标准输出(stdout)的函数
1.getchar putchar
2.gets puts
- gets:从标准输入读字符。直到出现换行符或读到文件结尾为止。不会检测空间是否足够,会造成空间越界。
- puts:向标准输出设备输出一个字符串,会自动添加换行符。
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(int argc, char *argv[])
{
char arr[8] = "";
int len = sizeof(arr) / sizeof(arr[0]);
printf("请输入小于%d个字符的字符串:\n", len);
gets(arr);//运行时会出现断错误
system("pause");
return 0;
}
3.sanf printf
- sanf:遇到空格、回车、tab键都会结束输入。即不提取后面继续输入的字符。
4.sscanf sprintf
scanf:解包
- 遇到空格、回车、\0、\t、\v、\f。均结束提取(简单地说就是空白字符与\0都会结束sscanf的提取)。
- sscanf(buf, "%c3%c", &ch1, &ch2); buf与format字符串中有匹配项可以跳过,比如3。
- 跳过数据:%*d %*s
- 指定提取宽度:%3s %*2s
- 指定提取范围:[a~zA~Z0~9] [aBc]
- 取反%[^a]
sprintf:组包
- 格式化字符串
- 字符串连接
- 把数字转成字符串
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int