新增了文档目录,并且写了一点第三节
This commit is contained in:
32
Chapter3/C3-输入输出专题.md
Normal file
32
Chapter3/C3-输入输出专题.md
Normal file
@@ -0,0 +1,32 @@
|
||||
# 目录
|
||||
- [目录](#目录)
|
||||
- [第三章 输入输出专题](#第三章-输入输出专题)
|
||||
- [内容](#内容)
|
||||
- [格式化输入输出函数](#格式化输入输出函数)
|
||||
|
||||
# 第三章 输入输出专题
|
||||
|
||||
input & output -> I/O(标准IO,文件IO)
|
||||
|
||||
|
||||
|
||||
## 内容
|
||||
|
||||
1. 格式化输入输出函数:`scanf`,`printf`
|
||||
2. 字符输入输出函数:`getchar`,`putchar`
|
||||
3. 字符串输入输出函数:`gets(!)`,`puts`
|
||||
|
||||
|
||||
|
||||
## 格式化输入输出函数
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
```c
|
||||
int printf(const char *format, ...);
|
||||
format: "%【修饰符】格式字符",参照图片标准输出修饰符和格式字符
|
||||
|
||||
```
|
||||
|
||||
49
Chapter3/IO/printf.c
Normal file
49
Chapter3/IO/printf.c
Normal file
@@ -0,0 +1,49 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/***
|
||||
* printf("%[修饰符]格式字符", 输出表项);
|
||||
*
|
||||
*/
|
||||
|
||||
#define STRSIZE 10
|
||||
|
||||
int main()
|
||||
{
|
||||
// printf("hello world\n");
|
||||
|
||||
// char ch = 65;
|
||||
// printf("%c\n", ch);
|
||||
// out: A
|
||||
|
||||
int i = 255;
|
||||
float f = 123.45678;
|
||||
char str[STRSIZE] = "helloworld";
|
||||
double dou = 123.456;
|
||||
long long l = 123456;
|
||||
|
||||
// printf("f = %8.1f\n", f);
|
||||
// out:f = 123.5
|
||||
// printf("i = %2d\n", i);
|
||||
// out: i = 123
|
||||
|
||||
// printf("%-10.5s[over]\n", str);
|
||||
// printf("%+10.5s[over]\n", str);
|
||||
// out:
|
||||
// hello [over]
|
||||
// hello[over]
|
||||
|
||||
// 同样对于i进行八进制核对十六进制的输出
|
||||
// printf("i = %#o\n", i);
|
||||
// out: i = 0377
|
||||
// printf("i = %#x\n", i);
|
||||
// out: i = 0xff
|
||||
|
||||
// printf("dou = %lf\n", dou);
|
||||
// printf("l = %ld\n", l);
|
||||
// out:
|
||||
// dou = 123.456000
|
||||
// l = 123456
|
||||
|
||||
exit(0);
|
||||
}
|
||||
Reference in New Issue
Block a user