2025-08-18 20:01:21

This commit is contained in:
swangnice
2025-08-18 20:01:21 +08:00
parent 8a920994bf
commit 7c31f72eea
254 changed files with 29201 additions and 3566 deletions

View File

@@ -2,4 +2,54 @@
title = 'C'
date = 2024-09-20T04:17:50Z
draft = false
+++
+++
<!-- 笔试题有的时候不给正常输入只给plain text -->
## Format Specifier
Common specifiers:
```
%d int
%u unsigned int
%c char
%s string (char s[])
%p void*
%ld long
%lld long long (64bits)
%f float/double
%lf float/double(usually used in scanf)
```
We can extend the format specifiers:
``` C
printf("%5d", 33); // width " 33"
printf("%.2f", 3.14159); // precision "3.14"
printf("%8.2f", 3.14159);// " 3.14"
printf("%-5d", 33); //Alignment "33 "
```
## IO
Read or print via terminal:
``` C
int x;
scanf("%d", &x);
printf("%d", x);
```
## Type Conversion
String to int, float....
``` c
int i = atoi("123");
double d = atof("3.14");
long l = strtol("123", NULL, 10); // safer, auto detec errors
double d2 = strtod("3.14", NULL);
```
Numbers to string:
``` c
int i = 123;
char buf[20];
sprintf(buf, "%d", i);
```