Sei sulla pagina 1di 437

Table

of Contents

1.1

1.2
GCC

1.2.1

1.2.2

Celling

1.2.3

Increment

1.2.4

printf

1.2.5

1.2.6

1.2.7

1.2.8

1.2.9

1.2.10

1.2.11

1.2.12

factorial

1.2.13

1.2.14

1.2.15

&

1.2.16

1.2.17

1.2.18

1.2.19

1.2.20

1.2.21

1.2.22

1.2.23

1.2.24

1.2.25

1.2.26

1.2.27

1.2.28

Gdb-

1.2.29

Gdb-factorial

1.2.30

Gdb-

1.2.31

Gdb-2

1.2.32

Gdb-

1.2.33

1.2.34

1.2.35

1.2.36

1.2.37

1.2.38

1.2.39

C50%

1.2.40

C-printf()

1.2.41

C-scanf()

1.2.42

(struct)

1.2.43

unionenum

1.2.44

C-putchar()getchar()

1.2.45

Cputs()gets()

1.2.46

&&

1.2.47

1.2.48

1.2.49

1.2.50

1.2.51

1.2.52

1.2.53

1.2.54

()

1.2.55

malloc

1.2.56

CNULL

1.2.57

NULL

1.2.58

1.2.59

1.2.60

1.2.61

1.2.62
3

1.2.63

1.2.64

1.2.65

1.2.66

(struct)

1.2.67

typedef

1.2.68

##

1.2.69

&&&

1.2.70

1.2.71

C--fputc&fgetc

1.2.72

C-

1.2.73

C-

1.2.74

C-

1.2.75

C-&

1.2.76

1.2.77

&

1.2.78

C&&

1.2.79

1.3

C-extern C

1.3.1

C-

1.3.2

C-2

1.3.3

C-3

1.3.4

C-

1.3.5

C-

1.3.6

C-static,const,auto,register

1.3.7

C-typedef

1.3.8

C-&1

1.3.9

C-&2

1.3.10

C-&3

1.3.11

C-

1.3.12

C-1

1.3.13

C-2

1.3.14

C-

1.3.15

1.4

1.4.1

1.4.2

1.4.3

dlopen

1.4.4

1.4.5

CLinux

1.4.6

Linux-

1.4.6.1

Linux-

1.4.6.2

Linux-.bashrc

1.4.6.3

Linux-tree

1.4.6.4

1.4.6.5

time

description

2016-7

draft

2016-8

format all the code and write in english

C
C
C
C
C
CC
()() \
()C
()
C
C
&&
()

(gcc & gdb)

(Cbug)

C
&

redis
&&
level up

C merlin_c

wizardmerlin945@hotmail.com
merlin yu 2016-7-30

1. C50%
2. &
3.

GCC

GCC

-ggdb
gcc -g -Wall HelloWorld.c - o hello

.
%

%%%.

10

Celling

Celling
4K Bytesblock4K Bytesblock; 4K
Bytes and 1 bit 2 block.
Floor x [x],floor
()
Ceiling0.5 1
C

11

Celling

12

Increment

increment
1

(initialize);
(argument).

13

printf

printf
printf

14

15

16

int
https:\/\/www.zhihu.com\/question\/40437296
(modelo)

: temp \/ 1 % 10
: temp \/ 10 % 10 (10)
: temp \/ 100 % 10
: temp \/ 1000 % 10
...

1234,
1234\/100 % 10 = 12.34 % 10 = 2.34
C 1234\/100 % 10 = 12 % 10 = 2
(C a = (a\/b)*b + a%b , c \/ truncate toward zero)

C
charunsignedsigned, &

17

,: ,,

14100
2400
: leap year
36554846365.24219
tropical year3650.2422
2229366
0.00783
400
4001700180019002000
,,
,""
0.00784616
1015821051015
365.242541
354120.367130
111355
1211
24
13384385

100 200 300 400


4100,200,300,400
()100,200,3004400

400
4

18

%100==0

4100400
C
if(n%4==0 && n%100!=0 || n%400==0 && n%100=0)
condition( 400 = 100 * 4400100)
if(n%4==0 && n%100!=0 || n%400==0)
(! - +) > > >

19

xyy1\/2
y >=1\/2 ceil() floor().

gcc -Wall a.c -o a.out


\/tmp\/cchxL3At.o: In function `my_round':
a.c:(.text+0xa8): undefined reference to `ceil'
a.c:(.text+0xc1): undefined reference to `floor'
collect2: error: ld returned 1 exit status
gcc
gcc -Wall a.c lm
-lm
6

if(decimalDigit >= 0.5)

20

int tmp = 1000000;


if(decimalDigit*tmp >= 0.5*tmp)

21

fabonacci


1 1 2 3 5 8 13 21
f(0) = 1, f(1)=1,
f(n) = (f-1) + f(n-2) (n>=2)

22

fabonacci----
----(Computer Algebra) Symbolic Computation

23

Euclid)

mac,window,linux

(greatest common divisor)


(n>m>=0)
1. gcd(n,m) = m , n%m==0
2. gcd(n,m) = gcd(m, n%m), n%m!=0
n%m

24

gcd(n,m) = m , n%m==0
gcd(n,m) = gcd(m, n%m), n%m!=0

()Page86,

: (m0n,m n>m>=0)
1. gcd(n, m)=n; m=0;,
2. gcd(n,m) = gcd(m, n%m), n>0

25

n%mnm0m
,
n>m>=0

n,mn>m
(m,n)
1. m,n-------------

2. m,n(m),-------------

n,m

n>=0, m>=0, m,nm,nm,n


gcd(n,m)gcd(m,n)n,m

26

5%3=2; 3%5=3

( n>m)
, my_gcd(4,6);

return n%m ? my_gcd(m,n%m) : m ;

return m>0 ? my_gcd(m, n%m) : m ;


(m,)

my_gcd(4,6) -- ---> my_gcd(6,4%6) my_gcd(6,4)


m>=0, n>=0m,n(
)

27

lisp

( 1)

1. nsqrt(n)a, bsqrt(n) ~
n.
(a < sqrt(n) < b < n a,bsqrt(n) a*bn
n)
csqrt()

28

1. i++ i+=2 ( gccloop <An Introduce to


Gnu C Compiler>)

29

sqrt(n)nsqrt(n)
(2)
n

n4*2*2*

30

lisp
0~sqrt(n),i
i-> i+1 > i+1+1 > .

31

2----

32

33

factorial

factorial
factorial

base

34

factorial

int

35

9
0~1009?

printf(%d\n,9) printf(%d\n,i)
--------------increase by one?
0-9910-20-30-40-50-60-70-80i
10
91
91091
(891)

36

1,2,3,4,5,6,7,8,10,11,

37

j=1
1x2=2, 2x1=2

38

39

&

&
C99complex.h_Complex
struct
Z = X + Yi;

40

&

{}fieldinitializer0
{}

41

&

{}initializer
c99

Z = r * e ^(i A); \/\/rA

42

passed by value---
mainadd()zz1,z2;
add
z1

z1 z1addz1

z1valuestruct complex_struct
tmptmpvaluemainz
mainmain
43

44

main add(), sub(), mul(), div();


add()sub(),
Z = X + Yi;
mul(), div(), Z = r * e ^(Ai);

----- > ----->

get_real_part(); get_virtual_part();
get_magnitude()r, get_angle()A
get_xxx()


()

45

2\/
\/

\/

46

47

prinrt_complex()
get_real() , get_virtual()

48

get

get01

49

50

-
0
0

-->
1.

1.

51

1. print

double

4
is_valid(R r);\/\/
formatR(R r); \/\/---call by add(), sub(), mul(),
div()
getGCD(int a, int b);
getLCM(int a, int b); \/\/\/\/,

52

Is_valid & Format

53

fotmat

54

formatformat

55

printR()formatR()add()

gcdlcm

56

57

58

59

-
&

a[N]

int count_random(int value);


print_random()

60

61

---

62

C
[10,20]

63

srand()rand()
rand()srand()seed,
, rand()1
srand() void srand (unsigned int seed);
time(0)seedtime(0)
#include<time.h>

()Ainput
ouput
inputoutput
inputinput,

64

1. 1
2. 0~bound-1N
bound*NN

65

( )
void pint_random_pattern(int[], int);

66

i,j

67

swap()
int swap(int[], int length, int i, int j); \/\/
length

68

global variableN

69

a[3]= {1,2,3}; P(3,3)C(3,m) (3


3)
P(3,3)32
1

NM
NM
()
Page 93

70

printf(%s,str) char str[]\0printf()

gcc -Wall main.c

1010
NULL

71

initializer
(multi-dimensional array)

72

print_day()
printf(%s\n, days[day]);
ifcase:

73

74

-
(scissor) (stone) (cloth)

Ctrl+ Zgame

75

()

76

scanf(%s, str); str


rvalue
lvalue

77

Gdb-

Gdb-
gdb

gcc Wall
-g

-g

78

Gdb-

main1 add_range0

110
gdb a.out

79

Gdb-

(start)

set var sum=0 set sum=0

80

Gdb-

81

Gdb-factorial

Gdb-factorial
break point

82

Gdb-factorial

factorial(1)

factorial(2), main

83

Gdb-factorial

(mainreturn 0;
libc
main)
C

84

Gdb-

Gdb-
start main

sum

sum = sum*10 + input[i] \0


: 123, ()
sum = 0*10 + 1 = 1
sum = 1*10 + 2 = 12
sum = 12*10 + 3 = 123
input[i] !=\0
while(1)

input
\0

85

Gdb-

for\0

sum=0
gdb

sum
gdb:

86

Gdb-

breakpoint

123123

87

Gdb-

forsum
a.out

88

Gdb-

sum, display sum

()
scanf()scanf()

b 14 if sum!=0 (
sum)

89

Gdb-

90

Gdb-2

Gdb-2

olleh

Reverse_str[0] ,[1]~[5]

91

Gdb-2

gdb
n=4reverse_str = 0000lleh;

\000NULL

92

Gdb-

Gdb-

GdbInput

93

Gdb-

x (, char7)

6input[5]input[5]

12345\0
NULL
12345

Input[5] 5
123456

94

Gdb-

Input5123456input12345
input[5]!=\0,sum
printf();NULL
\0
input[5]
watch input[5]

123456

1234567

95

Gdb-

watch -------------
i watchpoints -------------

96

97

98

99

100

101

1.

102

i-1i

103

i-1[i]

104

105

i0~len-1

106

107

We use loop invariants to help us understand why an algorithm is correct.


Loop invariant

108

n-1n
http:\/\/www.cnblogs.com\/bamboo-talking\/archive\/2011\/02\/05\/1950197.html
(loop invariant)(induction):
When the first two properties hold, the loop invariant is true prior to every iteration of the
loop.
Note the similarity to mathematical induction, where to prove that a property holds, you
prove a base case and an inductive step.
Here, showing that the invariant holds before the first iteration is like the base case, and
showing that the invariant holds from iteration to iteration is like the inductive step.
The third property is perhaps the most important one, since we are using the loop invariant
to show correctness.
It also differs from the usual use of mathematical induction, in which the inductive step is
used infinitely;
Here, we stop the "induction" when the loop terminates.

109

(loop invariant)(induction)

(loop invariant)
(loop invariant)(induction)

INSERTION-SORT(A)
1 for j 2 to length[A]
2 do key A[j]
3 Insert A[j] into the sorted sequence A[1 j - 1].
4 i j - 1
5 while i > 0 and A[i] > key
6 do A[i + 1] A[i]
7 i i - 1
8 A[i + 1] key
Initialization: We start by showing that the loop invariant holds before the first loop iteration,
when j = 2. A[1]
The sub-array A[1 j - 1], therefore, consists of just the single element A[1], which is in fact
the original element in A[1].
Moreover, this sub-array is sorted (trivially, of course), which shows that the loop invariant
holds prior to the first iteration of the loop.
Maintenance: Next, we tackle the second property:
Showing that each iteration maintains the loop invariant. Informally, the body of the outer for
loop works by moving A[ j - 1], A[ j - 2], A[ j - 3],
and so on by one position to the right until the proper position for A[ j] is found (lines 4-7), at
which point the value of A[j] is inserted (line 8).

110

A more formal treatment of the second property would require us to state and show a loop
invariant for the "inner" while loop.
At this point, however, we prefer not to get bogged down in such formalism, and so we rely
on our informal analysis to show that the second property holds for the outer loop.
Termination: Finally, we examine what happens when the loop terminates.
For insertion sort, the outer for loop ends when j exceeds n, i.e., when j = n + 1.
Substituting n + 1 for j in the wording of loop invariant, we have that the sub-array A[1 n]
consists of the elements originally in A[1 n],
but in sorted order. But the sub-array A[1 n] is the entire array! Hence, the entire array is
sorted, which means that the algorithm is correct
At the start of each iteration of the for loop of lines 1-8, the sub-array A[1 j
- 1] consists of the elements originally in A[1 j - 1] but in sorted order.
A1j-1
1j-1
for(
)
Initializationj2A[1 .. j-1]A[1],
A[1]
Maintenance
Termination,A
j=length[A]+1A[1 ..
length[A]]

loop invariant
A
1j-1

111

112

0~n-1a[0]1~n-1
a[1]

113

114


len=1left<right

origin[] [start, end]fresh[]

115

middle
merge
origin[]
copycopy
02^kcopy the
rest

116

merge
1len=1
merge_sort()

117

mergemergestart, end
,0235merge

118

merge
merge_sort()merge()
mergemerge

0(
2^k)

119

C50%

C50%
50%
1. &
2. & & &
3. & & & &
4. & (++)
5. (& + )
6. &
7. =+
8.

1.

120

C50%

: extern, register, static, volatile;


define, undef, include, ifdef, ifndef, endif, line

( + + +
)
&

()

: (0, 0x)(long L, unsigned u) (short , int , long) (


)
: +
3.14E-6 ;
f
: + \ddd
31\xhh1~2
&
+ #define PI 3.14
( + ) (sizeof() ) (
) ascii

1.

1. :

1. &
(\0nn+1)
1.
2. &

121

C50%

(stdio.h)
printf(), scanf(),
putchar(), getchar()
puts(), gets()

122

C-printf()

C-printf()
C

printf()
()
printf(, )
%e %g&
%p %%

123

C-printf()

( &)

int %d, %o, %x (int%c255)


: %f, %g, %e
% [*] [] [] [.] []

\n \f\r\t#

124

C-printf()

(630)

&

125

C-printf()

()

33

126

C-printf()

short %hd ; long %ld


[*] %5d,
5%*d

127

C-printf()

% [*] [] [] [.] []

128

C-scanf()

C-scanf()
C

scanf()

scanf(, );

129

C-scanf()

(
)
()

130

C-scanf()

\n

% [*] [] [] []

131

(struct)

(struct)

Content

1.

132

(struct)

2.

133

(struct)

134

(struct)

135

(struct)

. .

136

(struct)

()

137

(struct)

(*p).namemerlin.name
->

138

(struct)

copy

struct person char*init()name, address


char* name char* address
void*init()

address unsigned char * malloc


char
()
main.c

139

(struct)

140

(struct)

assert()

person_1
person_2

141

(struct)

malloc

print_struct()

142

unionenum

unionenum

union

.->

struct
x&

struct

int0,1,2

143

unionenum

()

blue4

enum meta_color RED;


()
enum meta_color{red, green, blue} RED = red;
switchstate

144

C-putchar()getchar()

C-putchar()getchar()
C

putchar()
(stdio.h)
printf(%d, c);

getchar()
getchar() ()-----

145

C-putchar()getchar()

146

C-putchar()getchar()

147

C-putchar()getchar()

gets()
segment fault

148

Cputs()gets()

Cputs()gets()
C
puts() ----- ()

gets()--------------input
scanf(%s, a)

gets()

149

Cputs()gets()

(s)

150

&&

&&

: &
() (void

&
\/ %
&
&

-a + b\/2 c*5 b\/2c*5&

(i++) + (i++) + (i--)


--j - (--j)




return

151

&&

doublefloat&

intchar8
charint127char127
8

152

&&

128 10 000 000 --- > int 000 000 00 xxx(2)


10 000 000128
100 000 00 xxx(2) 10 000 000-128
longint&

()

153

&&

()
int a, int b; \/\/a,bint
long result = a*b; \/\/a*bint
long result = (long) a * b; \/\/long*

long result = (long) (a*b);


alonga

154

&&

12

int a=0,b=0;a=0,b=0;

00 x>y>z ( (x>y)>z
)

ascii

> && > || && ||

sizeof
sizeof &
sizeof(i+1)sizeof(i)
&void

size_t

155

&&

size_t C

64ubuntu8
?

156

&&

(8)

()

sizeof i+1 sizeof(i) +1

157

&&

? :

int i;

int a=b=c=100; \/\/ a=b=c=100;

158

&

fun(i, ++i)
&

()----

auto: C
static: static

159

0\0

staticstatic

register:RAMcpu

160


&register
register
extern: extern

----extern

161

162

ab
bextern
()

()static static

externextern

163

input.c

164

output.c

process.c

165

166

0. 1.

first.hfirst.c

maintest_firstmain
extern

167

168

C
C

int array[10];

c99

169

index&
C

core dump

int a[8] = {1,2,3}; \/\/0


0 int a[8] = {0}; \/\/

int a[3] = {1,2,3}; \/\/


()
int a[] = {1,2,3}

a[0]a[0]~a[n-1]
a[n-1]a[n-2]a[n-2]a[n-2]a[n-3]a[0]a[1]
a[0]
a[1](a[0])
.

170

171

172

4,6,5,4

a[n-1]a[n-2]a[n-2]a[n-3]

a[2]a[1]

173

174

175

[] void print_array(int a[]);


const void
pirnt_array(const int a[]);
NUM

()
NUM

176

acopy
a
resulta

2 {1,0,0,3,4,0,5} , {1,3,4,5}

177

178

179

180

#include <stdlib.h>

malloc

181

[][];
float array[2][3];
C java

array[2][3]
A[0][0] -> A[0][1] -> A[0][2] -> A[1][0] -> A[1][1] -> A[1][2]
()


int array[2][3] = {{1,1,1}, {2,2,2}}; \/\/

: int array[2][3] = {{1},{2}};

0 0 0
0 0 0
0 4 0
int array[3][3] = {{},{},{0,4,0}};

182

C
()

183

&
char c[] = {G, o, o, d};
\0NULL \/\/sizeofstrlen\0

\0
\0
: \0, ascii0

char c = \0; char c = 0; (ascii0)


char str[] = {sfasfa} char str[] = {s,o,s}
\0
\0

<string.h>

(VClinux)
extern char *strlwr(char *s);
extern char *strupr(char *s);

184

185

extern char *strcmp(char *s); \/\/>=<


if( srcmp(s1, s2) == 0 ){ }

186

extern int strlen(char *str);

extern char *strcat(char *dest, char *src);

187

destdest; destsrc
dest\0\0

strcat()

extern char *strcpy(char *dest, char *src); \/\/


extern char *strncpy(char *dest, char *src, unsigned int n); \/\/
destsrc

188

extern char *strncpy(char *dest, char *src, unsigned int n); \/\/
: n>dest
nsrcsrcndest (\0)
nsrcsrc\0.

189

190

-
C()
key word

strncpy()

191

thathathatthat

192

srcoffset
thathathat
that
strncpysrccopytmp
len=4Offset
thathathat3tmpthat

193

continueelse

src

194

offsetkey_word len

(key_wordkey_word
thattkey_word thatt
key_word- = 4-1 = 3 )
---Unix

195

key_word
amixthathathat
4amix()

4i++4key_word

offset

196

offset =
that offset = (4) (1) =3
&
----- > KMP (prefix & postfix
offset)
KMP

197

()

()

198

()

199

()

64ubuntu

200

()

201

()

&a

202

()

203

()

---C
a[0][0]? (a+1
)

204

()

pa

205

()

()()**

206

()

a[M][N]a[m][n] a[m*N + n]

207

()

, *a*(a+i)(*(a+i)+j)
*(*(a+i) + j)
(*(a+i)+j) a[i]+j ij &a[i][j]
*(*(a+i) + j) a[i][j]

208

()

*(a[i] + j) *( *(a+i) + j )

209

malloc

malloc
:
malloc size void* void*
C,C++void*

()
NULL
free()

mallocmemory allocation

malloclibcsource code
includestdlib.hgccerrormalloc was not declared in this scope
malloclibclibcmalloc
Run-time

malloc:

double *pd = (double*)malloc(sizeof(double) * 12);


malloc(0);

210

malloc

Linuxmalloc(0),Linuxmalloc16Bytes
malloc(-1)malloc(0)

211

malloc

(
NULL)

212

malloc

(mallocchar*a, a!a!=0
NULL(void*)00x00000000
)

NULL

213

CNULL

CNULL
NULL
NULL
#undef NULL
#if defined(__cplusplus)
#define NULL 0
#else
#define NULL ((void *)0)
#endif
node
int *node = NULL;

int *node = (int*)0; \/\/Cint *node = 0;C++


int *iPtr3 = 1; \/\/error: invalid conversion from `int' to `int*'

214

NULL

NULL
NULL

215

NULL

funfun(int*)node
node
fun

216

NULL

node(nil)0
funnode&N,
N*node
100.
node04
(nil)
0

217

NULL

218

int (*p)[N] int *p[N]

: ()

219

int (*p)[N]; pp

pNintp++Nint

int *p[N]

(c[M][N])
2()
?

220

strcpy()

strcpy()targetsource
target,source

221

strcat();

222

str_cmp()

223

224

()

()

225




(*) ();

p = ; p = & ;
(*p)()

226

void (*p)(int*)

[a,b]

227

[a,b]

* ()

228

0.

1.

229

230

()
*[]
int *p[3]; (3)

a[3][n] a[0] , a[1] , a[2] *(a+0), *(a+1), *(a+2)


&a[0] , &a[1] , &a[2]&a[0]
(
(a+i)i
*(a+i))

231

232

4 x 3 =12 Bytes

233

234

int *p[N] int (*p)[N];

int (*p)[N]*p[i]i0p[i]*(p+i)
p[i]+j ( *(p+i) +j )
*( *(p+i) +j ) *(p[i] + j)
int *p[M] p[0]~p[5]p[0]


char *p[M]; \/\/
char p[M][N]; N(
)

235


.
()

**;
:

236

237

main
mainmain

(
)

238

.i
&

( # ##)
#define #undef
#include
#if #ifdef #ifundef #elif #else #endif
#error #line #pragma
(slash \)

#define #undef
()

(typedef)

#define PI 3.14
#define LD (long double)

#define ()

#define MAX(x,y) ( ( (x)>(y) ) ? (x) : (y) )


#define PRINT(i) printf(%d\n,i)
max = MAX( x, MAX(y,z) );

239

#define
#undef #undef PI
MAX

#define R 5
#define R*R

()

http:\/\/blog.csdn.net\/yuanlong_zheng\/article\/details\/7545032

C
(_)

240

__LINE__ Bug---%d
__FILE__ ---%s
__DATE__Mmm dd yyyy ---%s
__TIME__ "hh:mm:ss"-----%s
__STDC__ C1 ()

__DATE__ __TIME__

__FILE__ __LINE__

241

242

243

1.
2. Window Unix Linux----
3. -----

244

__STDC__CC
1.

a.hb.h c.hb.h a.hc.ha.hb.h


c.hb.hc.ha.hb.h

a.h

245

246

#error

#error

#line

#pragma

#pragma
directive.

247

&

248

249

250

Makefile

251

(struct)

(struct)

--------

()

unsigned int

252

(struct)

2
18

253

(struct)

01

254

(struct)

()

255

(struct)

bit.c -2
struct byte_struct
1 3
4int

----

256

(struct)

bit8 c 10 ; b 11 ; a 01 ()
bit.a = 1;
bit.b = 3;
bit.c = 2;
%d4
http:\/\/www.cnblogs.com\/bigrabbit\/archive\/2012\/09\/20\/2695543.html
http:\/\/www.cnblogs.com\/pure\/archive\/2013\/04\/22\/3034818.html
http:\/\/www.cnblogs.com\/Logic0\/archive\/2009\/09\/14\/1850340.html

257

typedef

typedef

typedef ;

typedef #define
#definetypedef

typedef

1.
2.
3. typedef
4.

int a[100] ;

ARRAYarray_aint [100]

258

typedef

-----

size_t

size_t
unsigned int , unsigned long

259

##

##
###
###definetypedef

typedefStudentstruct
_tag_Student

260

##

s2

Student
Student s1;

, :

, Phone phone1;

261

##

? : ()

, ,.

##

262

##

##
type
http:\/\/blog.csdn.net\/kangear\/article\/details\/8456115

263

&&&

&&&
IO
&


&

&
& (ascii)

ascii

123ascii
123int
Short2

stream
&

-----

(&)

264

&&&

()
stdin
stdout
stderr
&

&

& ---\/
----

265

&&&

-----
C()
IOIO
C
IO

flush

(flush)

IO
()
Linuxstdio.h (FILE)

266

&&&

267

C
FILE

FILE
()

_cntcount
File status flags10
0_F_READ _F_WRITE

268

FILE *pFile;
FILE file

(t stands for text)


rt
wt
at
(b stands for binary)
rb
wb
ab
+

rt+
wt+
at+

269

ra

fclose(pFile);

pFile

fcloseall()

fgets(str, n, pFile)pFilenstr

270

readme.txt ()

271

ascii
ascii

272

C--fputc&fgetc

C--fputc&fgetc
fgetc();

CEOF-1 ; ascii0~127-1

EOF
content

-1feof()
10
fgetc()
fputc();
()

copy

273

C--fputc&fgetc

fgetc()fputc() putc()getc()
: putc()getc() putchar()getchar()

274

C--fputc&fgetc

275

C-

C-

rewind() ferror
fseek()
int whence SEEK_SET 0; SEEK_CUR 1;
SEEK_END 2
long offset longoffsetbase

fteel() -1
ftell(pfile)
0
fseek()-----ftell(pfile)

276

C-

C-

fread()fwrite()
man

The function fread() reads nmemb elements of data, each size bytes long, from the stream
pointed to by stream, storing them at the location given by ptr.
The function fwrite() writes nmemb elements of data, each size bytes long, to the stream
pointed to by stream, obtaining them from the location given by ptr.

On success, fread() and fwrite() return the number of items read or written.
This number equals the number of bytes transferred only when size is 1.
If an error occurs, or the end of the file is reached, the return value is a short item count (or
zero).
fread() does not distinguish between end-of-file and error, and callers must use feof(3) and
ferror(3) to determine which occurred.

nmemb * size

short
feof()ferror

277

C-

size, strlensizeofnmemb1 .

278

C-

279

C-

C-
&

writer(read)

man

( &status)
NULL fflush(NULL);

man setbuf
buffer
Normally all files are block buffered. When the first I\/O operation occurs on a file,
malloc(3) is called, and a buffer is obtained.
If a stream refers to a terminal (as stdout normally does), it is line buffered.
stderr
bufferbuffer

280

C-

: setbuf(pfile, null); setvbuf(stream, buf, buf ? _IOFBF :


_IONBF, BUFSIZ);
char *buf buf
mode
size buffer
The function setvbuf() returns 0 on success.
It returns nonzero on failure (mode is invalid or the request cannot be honored).
It may set errno on failure.
char *bufsize
size, buffer
size

281

C-

buffer size15,11fputcBufferbuffer

test.dat
fclose

282

C-

bufsize1010
shelltest.dat9

fclose

283

C-

Buffer
----

284

C-

285

C-

test.dat

fclose()

286

C-

11

11
12
11fclose

287

C-

10

fclose

288

C-

289

C-&

C-&
EOF-1
-1feof(pfile)

feof(pfile)-----
ferror()----
Linux

rewind()clearerr()
The function fileno() examines the argument stream and returns its integer descriptor.
-1

These functions should not fail and do not set the external variable errno.
(However, in case fileno() detects that its argument is not a valid stream, it must return -1
and set errno to EBADF.)

290

C-&

291

fwrite & fread

292

fwrite

293

ticks.bin

294

()

print_struct()

295

296

&

&

ANSI Cmemset&

malloc();
calloc();
realloc();
free();
man

mallocsizeNULL;
mallocnsizeNULL;
reallocptrsize

<stdlib.h>
void*

297

&

298

&

299

C&&

&&

http:\/\/blog.csdn.net\/zhenghui1\/article\/details\/8684236
()linux

windowkernel

main.h

300

C&&

main.c

301

C&&

302

C&&

mm
scanf()
menu

1~7scanf

stdinscanfnewline

stdin\n

303

C&&

getchar()stdin\nascii10

&&while

clearlinuxstdin

304

C&&

emacs gui

305

C&&

306

C&&

freadrecord
cur_info

307

C&&

308

C&&

tmp

309

C&&

tmp

low

310

C&&

311

C&&

312

C&&

worker_info

CC

313

314

C-extern C

C-extern C
androidexternal\/sqlite\/androidsqlite3_android.h

what that means ?


(
__cplusplusldcc++
)

externauto

315

C-

C-

1. &
2. & -----
3. &

-----Userspace

C55

316

C-

intel

linuxnmreadelfsize

317

C-

static

alloca
cpu

mainmalloc

---

static

cpu

318

C-

malloccalloccalloc
calloc0memset

reallocptr

319

C-

alloca()size

c11
size_t alignmentsize

320

C-2

C-2

1. NULL

2. (char*)

3.
4.
5. C99--
calloc
6. callocmallocmemset
6.NULLNULL

1.

---------
1.
2.
3.
4.

321

C-2

listptr

gcc

322

C-2

323

C-2

linux

window

324

C-2

sizeof()

325

C-2

0C99null

-std=c99

funbufferbufferbuffer_size

buffer_size 0
int *buffer = NULL;

326

C-2

calloc

memset(ptr, char, sizeof()) calloc

ptrNULLNULL

NULLptr
NULL
1.
2.
NULLNULL

()

fun*pfunfun
free
p

327

C-2

(out of buffer, bound, index)


CJavaC++

&

---

----

setvbuf()
flush

Programmer

google

http:\/\/blog.csdn.net\/RING0LYY\/article\/details\/8279286

free

328

C-2

1. ----------
2.

3. strcpy, strncpy'\0,
memcpy, sprintf
&
3.'\0---strlen()'\0'---memcpy
strlen()+1
strncpy()target'\0()

snprintf, strncpy, strncat, fgets------


memcpystrcpy
C

329

C-3

C-3

>
--->free()
---->
----->

free
p

330

C-3

p->namep

C125 Page 416

f2()f1()

331

C-3

f1()

332

C-

C-

&

char array[]'\0

\0ascii0NULL

'\0sizeofstrlen1

char array[7]
'\0
char array[] = {h, e, l, l, o};
'\0

333

C-

(gcc)

const const char *array = hello;

const

334

C-

strlen

size_t64unsigned long int

strlen( x ) > = strlen( y ) strlen ( x ) - strlen( y ) >=0


0
sizeof

sizeof

\/
&

335

C-

strcpy destsrc

strncpynsrcdest
mm+1
mm------strlen(src)n
memcpy

size_t n srcdestC

dest

strcpystrncpystrcpy

strcpydestsrcstrcpy(p+1,p)
core dump

336

C-

memcpy

memcpy(p, p+1, sizeof(xx)*n)

337

C-

gccoverlap

memcpycpy

338

C-

339

C-

ifoverlap
else

memmove
The memcpy() function copies n bytes from memory area src to memory area dest.
The memory areas must not overlap. Use memmove(3) if the memory areas do
overlap.

340

C-

memmove

memcpy

341

C-

Cgcc
memcpy()memmove()
&
strcmp0

strcmp

342

C-

s1s2

s2s1
0

343

C-

----sizeof()

gdbs1,s2

344

C-

s2s10

strcmp

345

C-

strncmp()

memcmp
s1,s2
memcmp
sizeof(char)1

memcmp4
strcmp, strncmpmemcmp

346

C-

347

C-

C-
strtok

char *strconst
const char *str
strtok

348

C-

debug

349

C-

strtok(input, ,);delim
strtoktoken
Each call to strtok() returns a pointer to a null-terminated string containing the next token.
This string does not include the delimiting byte.
delimtoken()
strNULL
(delim)

350

C-

351

C-

strtoknot reentrant
NULL

352

C-

POSIX strtok_r()

yesterday, I lost; today, i miss; tomorrow, i cherish

353

C-

data.txt

354

C-

buffer

(fgets() EOF )
127newline128
newline

buffer

355

C-

356

C-

357

C-

strtokstrtok_r

358

C-static,const,auto,register

C-static,const,auto,register
auto
auto

register
register()&

static

()

const
const
const

constdata

359

C-static,const,auto,register

&const

360

C-typedef

C-typedef
typedef

0.
typedef typedef

1.
2.
3. typedef
4.
100 int a[100]
typedef int ARRAY[100];
ARRAY array_a;

1. typedef

361

C-typedef

#define()
typedef

typedef int INT;


unsigned INT i; \/\/typedef
#define INT int; unsigned INT i;
define

typedef

2.

362

C-typedef

typedef unsigned int UINT64_T;


Ubuntu\/usr\/include\/stdint.h

()

3.
3

typedef
struct xxx

363

C-typedef

point

pointstruct point_tmp

4.

364

C-typedef

5.
6.const

365

C-typedef

typedef

const

& free
const string str

366

C-typedef

str
typedef:
const char* str;
char* const str;
typedefconst

367

C-typedef

typedefconst()

368

C-typedef

369

C-&1

C-&1

C
(signed)-------------
(unsigned)-------------

signed
32os64os

01

char
unsigned char 0~255
signed char 128 ~ 127

-----

+11.
4

370

C-&1

char
short
int
long
signed
unsigned
C99_Bool_Complex_Imaginary
signedunsigned

char
unsigned char
signed char
int
unsinged int
signed int
short int
unsinged short int
signed short int
long int
unsigned long int
signed long int
long long int
unsinged long long int
ANSI

371

C-&1

linuxusr\/include\/limits.h

sizeof()

372

C-&1

sizeof()long unsigned int


(size_tsize_t64ubuntulong unsigned int)

char

charunsigned charsigned char


ansi
-128~1270~2550~127
char

373

C-&1

ascii
char c = B; char c = 66;0~127ascii
signed char
c = 128
char c = B;

charunsignedsigned

charsigned charunsigned char


char

charsigned charunsigned char?

char c = 150;\/\/signed char


signed char
unsigned
gcc

374

C-&1

linuxubuntu64charsigned char

1500
-128~127CHAR_MAX

C99

gcc
(150 % CHAR_MAX 1 ) + (-128) = -106
(1-1281282-126
-127
127-128)

375

C-&1

gcc
(150 % CHAR_MAX 1 ) + (-128) = -106

%d

int%d
Linuxchar

376

C-&1

size_t
size_t\/
ubuntu64\/usr\/include\/linux\/stddef.h
\/usr\/lib\/gcc\/x86_64-linux-gnu\/5\/include\/stddef.h

unsigned int

377

C-&1

size_tsize_tunsigned int
unsinged long
size_tsize_t
unsigned long
unsinged int

unsigned long x;
size_t y;
y = x; \/\/

size_t

&

378

C-&2

C-&2
unsignedsigned

379

C-&2

strlen(str1) strlen(str2)size_t0
strlen(str1) >= strlen(str2) strlen(str1) strlen(str2)

380

C-&2

1 > -1wrong
size_t-1
-1 1111 1111 8

0xFF (3264F)

381

C-&2

strlen()

btw: strlen() sizeof()

382

C-&3

C-&3

unsigned char.
0~255
C99MAX+1
257257%(255+1) =1

(257-MAX - 1) + MIN

383

C-&3

add

384

C-&3

(type can hold)

385

C-&3

(a+bUINT_MAX)

buffermalloc

386

C-&3

C99

gccMAXMIN

buffer

buffersize

387

C-

C-
&




return

388

C-

longdouble

389

C-

doublefloat&

intchar8

charint127char127

8
128 10 000 000 --- > int 000 000 00 xxx(2
) 10 000 000128
100 000 00 xxx(2) 10 000 000-128

longint&

C-
OSer_Merlin
: 2016\/07\/29 15:25

390

C-

: 0
: 0
: 0
: 0
&




return

longdouble

391

C-

doublefloat&

intchar8

charint127char127

8
128 10 000 000 --- > int 000 000 00 xxx(2
) 10 000 000128
100 000 00 xxx(2) 10 000 000-128

longint&

392

C-

()
C

atoi(const char*)

----

393

C-

unsigned intsigned charunsigned intsigned char

intchar

signed int ----> unsigned int

UINT_MAX

394

C-

longint

395

C-

doubleint

double > float


long double > double
long double > float

396

C-

(limits.h)

123123
abc

397

C-1

C-1
C
()

C125495C

1. ()
2.
3. (nullNULL)
4. void
5. ()
6. const
7. ()----
8.
8
1.
2.
3.
4.
5. ()

&:

398

C-1

()

()

1.
2.
3. (sizeof)
4. ()

p*p

VS
()

<495c>5 C

399

C-1

(0(type*) 0)
C0(void*) 0NULL

C++ void*0
0 0 '\0', 3-3, (void*)0
(0)

nullNULL
nullnull
NULL C0 ((void *) 0)
NULL
(NULL free()NULL)
0((type*) 0),

C0 NULL0.
(pascalnil)

0
0
if(
)

if(p){...} //ok

---0char *p = 0; p
(00(char *)0vo
id*void*)
---0
NULL (NULL0,
0)
NULL0null0
0

0int(int *)0

400

C-1

NULL0L

intlong0L
NULLNULL
(C0)

nul
ASCII0'\0',NUL0.

#define NUL '\0'

#define Null_ptr(type) ((type *)0)


2
1. NULL 0
2. 0NULL

void

void* p void*
c++void \
void \
void
`(GNUvoid\char*++--)`
void*(
)
void (*)() int (*)()

union

401

C-1

1. () ()0
2. (
)
3. void*(
)

const
const int *p int *const p const
const
int _int _. const int

__ int__

402

C-2

C-2

1. C

2. (
)
3.

1. TT()
char *a char p[]
char *aa
char p[]pp
p[x]a[x]

2.

3.
&a[0]
void f(char a[]){} void f(char* a){}

4. ()

403

C-2

()
()

404

C-

C-
C
1. ~ & ^ |
2. << >> () (6
)

1.

x & 0x000000ffx8\(\)
x & 0xffffff008

0x00ff0xff00

2.

signed int i; \/\/644 i | 0x000000ff 81
&8|

3.
()

4.
() ?

405

C-

~x MAX-x MAXlimits.h
(
)
(&)

<< >>()
22

1. <<
x << y;//(y>=0) ( yx )
()()
12.
yx

2. >>
x << y;
x
01
: 0
2
1. ---0
2. ---1
12

int

406

C-


int x = 100;
long y = 200;
x & y;
(int)(01)

407

()

(shelllinux)

(redis)

(
()

(linux)
Linux

408

githubC&C
CSubSub

lib
dev-cpp(-std=c99)

linux

409

gcc

dev-cpp?

Compiling project changes...


-------- Project Filename: C:\Users\Merlin4720\Desktop\test\Project1.dev
- Compiler Name: TDM-GCC 4.9.2 64-bit Release
Building makefile...
-------- Filename: C:\Users\Merlin4720\Desktop\test\Makefile.win
Processing makefile...
-------- Makefile Processor: C:\Program Files \(x86\)\Dev-Cpp\MinGW64\bin\mingw32-make.exe
- Command: mingw32-make.exe -f "C:\Users\Merlin4720\Desktop\test\Makefile.win" all
gcc.exe -c main.c -o main.o -I"C:\/Program Files \(x86\)\/Dev-Cpp\/MinGW64\/include" -I
"C:\/Program Files \(x86\)\/Dev-Cpp\/MinGW64\/x86\_64-w64-mingw32\/include" -I"C:\/Pro
gram Files \(x86\)\/Dev-Cpp\/MinGW64\/lib\/gcc\/x86\_64-w64-mingw32\/4.9.2\/include" std=c99
gcc.exe -c lib\/cssArray.c -o lib\/cssArray.o -I"C:\/Program Files \(x86\)\/Dev-Cpp\/M
inGW64\/include" -I"C:\/Program Files \(x86\)\/Dev-Cpp\/MinGW64\/x86\_64-w64-mingw32\/
include" -I"C:\/Program Files \(x86\)\/Dev-Cpp\/MinGW64\/lib\/gcc\/x86\_64-w64-mingw32
\/4.9.2\/include" -std=c99
gcc.exe -c lib\/cssFile.c -o lib\/cssFile.o -I"C:\/Program Files \(x86\)\/Dev-Cpp\/Min
GW64\/include" -I"C:\/Program Files \(x86\)\/Dev-Cpp\/MinGW64\/x86\_64-w64-mingw32\/in

410

clude" -I"C:\/Program Files \(x86\)\/Dev-Cpp\/MinGW64\/lib\/gcc\/x86\_64-w64-mingw32\/


4.9.2\/include" -std=c99
gcc.exe -c lib\/cssList.c -o lib\/cssList.o -I"C:\/Program Files \(x86\)\/Dev-Cpp\/Min
GW64\/include" -I"C:\/Program Files \(x86\)\/Dev-Cpp\/MinGW64\/x86\_64-w64-mingw32\/in
clude" -I"C:\/Program Files \(x86\)\/Dev-Cpp\/MinGW64\/lib\/gcc\/x86\_64-w64-mingw32\/
4.9.2\/include" -std=c99
gcc.exe -c lib\/cssMap.c -o lib\/cssMap.o -I"C:\/Program Files \(x86\)\/Dev-Cpp\/MinGW
64\/include" -I"C:\/Program Files \(x86\)\/Dev-Cpp\/MinGW64\/x86\_64-w64-mingw32\/incl
ude" -I"C:\/Program Files \(x86\)\/Dev-Cpp\/MinGW64\/lib\/gcc\/x86\_64-w64-mingw32\/4.
9.2\/include" -std=c99
gcc.exe -c lib\/cssObject.c -o lib\/cssObject.o -I"C:\/Program Files \(x86\)\/Dev-Cpp\
/MinGW64\/include" -I"C:\/Program Files \(x86\)\/Dev-Cpp\/MinGW64\/x86\_64-w64-mingw32
\/include" -I"C:\/Program Files \(x86\)\/Dev-Cpp\/MinGW64\/lib\/gcc\/x86\_64-w64-mingw
32\/4.9.2\/include" -std=c99
gcc.exe -c lib\/cssString.c -o lib\/cssString.o -I"C:\/Program Files \(x86\)\/Dev-Cpp\
/MinGW64\/include" -I"C:\/Program Files \(x86\)\/Dev-Cpp\/MinGW64\/x86\_64-w64-mingw32
\/include" -I"C:\/Program Files \(x86\)\/Dev-Cpp\/MinGW64\/lib\/gcc\/x86\_64-w64-mingw
32\/4.9.2\/include" -std=c99
gcc.exe -c lib\/cssSystem.c -o lib\/cssSystem.o -I"C:\/Program Files \(x86\)\/Dev-Cpp\
/MinGW64\/include" -I"C:\/Program Files \(x86\)\/Dev-Cpp\/MinGW64\/x86\_64-w64-mingw32
\/include" -I"C:\/Program Files \(x86\)\/Dev-Cpp\/MinGW64\/lib\/gcc\/x86\_64-w64-mingw
32\/4.9.2\/include" -std=c99
gcc.exe main.o lib\/cssArray.o lib\/cssFile.o lib\/cssList.o lib\/cssMap.o lib\/cssObj
ect.o lib\/cssString.o lib\/cssSystem.o -o Project1.exe -L"C:\/Program Files \(x86\)\/
Dev-Cpp\/MinGW64\/lib" -L"C:\/Program Files \(x86\)\/Dev-Cpp\/MinGW64\/x86\_64-w64-min
gw32\/lib" -static-libgcc
Compilation results...
-------- Errors: 0
- Warnings: 0
- Output Filename: C:\Users\Merlin4720\Desktop\test\Project1.exe
- Output Size: 146.525390625 KiB
- Compilation Time: 3.91s

.o gcc -c xxx.c o xxx.o -I head_file_direcotry_xxx -std=c99

411

linuxmakefile
Makefile
main:main.c lib/*.c
gcc -Wall -g -std=c99 -c main.c lib/*.c
gcc -Wall -g -std=c99 *.o -o main
rm *.o

[4:30:21]init string Hello World


Hello World
[4:30:21]delloc string Hello World

dev-cpp gcc.exe main.o lib\/cssArray.o lib\/cssFile.o


lib\/cssList.o lib\/cssMap.o lib\/cssObject.o lib\/cssString.o lib\/cssSystem.o -o
Project1.exe -L"C:\/Program Files \(x86\)\/Dev-Cpp\/MinGW64\/lib" -L"C:\/Program Files \
(x86\)\/Dev-Cpp\/MinGW64\/x86\_64-w64-mingw32\/lib" -static-libgcc

:
gcc main.o x0.o x1.o x2.o x3.o... xx.o -o main - Llib_directory -static-libgcc

&

412

objectar.o.a
1 ar rcs xxx.a a.o b.o c.o

armanar --help.
gcc--shared
gcc lib\/*.c -o csslib.so --shared2
--shared()ar

-L
-l lib.a,-lm
-I #include
-static

-I-l LIBRARY_PATH
(ld) --static-libgcc ; -shared-libgcc

1
. ar rcs r , -s(ranlib libxxx.a)
2
. gcc -fPIC lib/*.c -o csslib.so --shared

413

Linux
shared library static library

include<stdio.h> printf() ,

C
1
gcc -fPIC -c main.c -o main.o
gcc -shared main.o -o libmain.so
C++
g++ -c -fPIC main.c -o main.o
g++ -shared main.o -o libmain.so

libxxx.so
lib
.so
xxx

414

nm libxxx.so
so
so

print_func.h
#ifndef PRINT_FUNC_H
#define PIRNT_FUNC_H

void print_io();

#endif

print_func.c
#include <stdio.h>
void print_io(){
printf("just a test.\n");
}

main.c
#include "print_func.h"
int main(void){
print_io();
return 0;
}

printlib.so

415

gcc -g -Wall -fPIC -c print_func.c -o print_func.o


gcc -g -Wall -shared print_func.o -o libprint.so

main
gcc -g -Wall main.c -L. -lprint

./a.out
just a test.

soLD_LIBRARY_PAT
export LD_LIBRARY_PATH=.
echo $LD_LIBARAY_PATH

gcc main.c -o main -L. -lmylib -static

ar src.o
1 PIC means position independent code

416

gcc

1.
2.linuxgcc

Linux-page 80-82
ubuntu64

&
css
(main.clibso)
gcc -Wall -g -std=c99 -fPIC -c lib/*.c
gcc -Wall -g -std=c99 -shared *.o -o libcss.so
rm *.o

libcss.so&main.c
gcc -Wall -g -std=c99 -c main.c -o main.o
gcc -Wall -g main.o -L. -lcss -o main

./main: error while loading shared libraries: libcss.so: cannot open shared object file:
No such file or directory

-L\/lib
\/usr\/lib

417

* so/etc/ld.so.conf
* LD_LIBRARY_PATH

echo $LD_LIBRARY_PATH 'export LD_LIBRARY_PATH=.'

load

man 3 dlopen,

()

LinuxGcc
(10)
1. ()
2. linux
(
)
3.
4. ar.o.a
5. gcc-fPIC,-shared.so
6. libxxx.alibxxx.so.major.minor (majorminor
)

418

7. ldd libxxx.so
8. ldd readelf -d
9. elfld-linux.so(loader&linker)
10. elfDT_RPATHLD_LIBRARY_PATH
\/etc\/ld.so.ache\/lib\/usr\/lib
11. export LD_LIBRARY_PATH=.
12. lib\/\/usr\/lib
13. ldconfig\/etc\/ld.so.cacheld config /usr/mylib
14.
15. -L, LIBRARY_PATH, /lib/usr/lib/usr/local/lib
16. -L, LD_LIBRARY_PATH, /etc/ld.so.conf, /lib/usr/lib
9

419

dlopen

dlopen
dlopenman
NAME
dlclose, dlopen, dlmopen - open and close a shared object
SYNOPSIS
#include <dlfcn.h>
void *dlopen(const char *filename, int flags);
int dlclose(void *handle);
#define _GNU_SOURCE
#include <dlfcn.h>
void *dlmopen (Lmid_t lmid, const char *filename, int flags);
Link with -ldl.
DESCRIPTION
dlopen()
The function dlopen() loads the dynamic shared object (shared library) file named by
the null-terminated string filename and returns an opaque
"handle" for the loaded object. This handle is employed with other functions in the d
lopen API, such as dlsym(3), dladdr(3), dlinfo(3), and
dlclose().

man

420

dlopen

#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h> //using dlopen()
#include <gnu/lib-names.h> /* Defines LIBM_SO (which will be a string such as "libm.so
.6") */
int main(void){
void *handle;
double (*cosine)(double);
char *error;
handle = dlopen(LIBM_SO, RTLD_LAZY);
if (!handle) {
fprintf(stderr, "%s\n", dlerror());
exit(EXIT_FAILURE);
}
dlerror(); /* Clear any existing error */
cosine = (double (*)(double)) dlsym(handle, "cos");
/*......*/
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
exit(EXIT_FAILURE);
}
printf("%f\n", (*cosine)(2.0));
dlclose(handle);
exit(EXIT_SUCCESS);
}

421

dlopen

(libdl.so)
gcc -g -Wall main.c -o main -ldl

./main
-0.416147

dlopendlsymdlcloseexit

dlsym()

422

dlopen

/* According to the ISO C standard, casting between function


pointers and 'void *', as done above, produces undefined results.
POSIX.1-2003 and POSIX.1-2008 accepted this state of affairs and
proposed the following workaround:
*(void **) (&cosine) = dlsym(handle, "cos");
This (clumsy) cast conforms with the ISO C standard and will
avoid any compiler warnings.
The 2013 Technical Corrigendum to POSIX.1-2008 (a.k.a.
POSIX.1-2013) improved matters by requiring that conforming
implementations support casting 'void *' to a function pointer.
Nevertheless, some compilers (e.g., gcc with the '-pedantic'
option) may complain about the cast used in this program. */

423

ar(.o)
ar cr libxxx.a xxx.o xxx1.o

.o ar t libxxx.a

.a nm libxxx.a (UCT)
grep

ar
1. xlibxxx.a.o
2. a .o (ranlib libxxx.as)
3. s
arranlib

424

CLinux

CLinux
C
COS

Linux ubuntu
()

1. linux
2. shell

LinuxOS()()
/
/

LinuxShell -

425

Linux-

uname -a

cat /etc/lsb-release

cat /proc/meminfo

ram

cat /proc/cpuinfo

cpu

getconf LONG_BIT

(2364)

lspci -v

pci-v

df -H

df-Hhuman readable

xinput

/proc

426

Linux-

Linux
linux()

1. &
2.
3. (debian-package)
4.
5. ()
6.
7. git(svn)
8.
9. ()
10.
11.

Linux

427

Linux-

ls

list files in current directory

ls -al

list all files in current dir, including dot


files

ls -al \

grep 'string'

cd
dirpath

change directory

cd

go to $HOME dir

pwd

show the current dir

show file name matching


string

echo $HOME home

treeMactreels

touch filename

create a new file, or update timestamp if it exists

rm filename

delete a file

rm -r dir_name

delete a directory

cp file_name new_filename

copy a file

cp -r dir_name new_name

copy a dir

mkdir new_dir_name

create a new dir

rmdir dir_name

delete a dir only if it is empty

mv file_name new_name

rename file, or move to a diff dir

du -sh name

show dir or file size, s = sum, h =

du(estimate file space usage)


du -sh --exclude='*.o' dir .o

du -k -m

428

Linux-

(cat, head, tail,file)


(emacs, vi)

cat fname

view a file

cat fname
\

more

head
fname

view the first few lines of a (big) file. (most useful for
log files.)

tail fname

view the last few lines of a file

tail -f
fname

view the last few lines of a growing file, updated


continuously

file fname

report what type of file it is(for example: text, jpg, png,


pdf)

view a file by
page

ls -l /usr/bin dxrw

type 'cmd'

show if cmd is a shell built-in or standalone program

which cmd

show full path of a command, useful for checking if a program is


installed

locate
fname

find a file by name using the database

updatedb

update the database used by locate

which $PATH
locate find dir_paths -name "*fname*"
updatedb

()

429

Linux-

ubuntudebiandpkgapt
apt

apt-get install name

apt-get remove name

apt-get purge name

()

apt-get update

sync package index files from sources

apt-get upgrade

dpkg -l

(grep)

apt-get dist-upgrade

1.
2.
3.
4. $PATH (/usr/local/bin)

tar zxvf filename.tar.gz


cd dirname
./configure #2
make #3
sudo make install #4

apt-cache show name

430

Linux-

tar (.tar)
gzip (.gz)
bzip2 (.bz2)
xz (.xz)
7zip (.7z)
rar (.rar)
zip (.zip)

linux tar gzip zip ,.


tar

tar cvf tar_name.tar dir_path

tar up a dir

tar xvf tar_name.tar

untar a tar_file

tar czvf tar_name.tar.gz dir_path

tar up a dir to .tar.gz

tar xzvf tar_name.tar.gz

untar a .tar.gz file

zip

zip -r zip_file.zip dir_name

zip a dir

upzip zip_file.zip

unzip

gzip

gzip filename

compress a file

gzip -d filename

decompress a file

bzip2

bzip2 filename

compress a file

bizp2 -d filename

decompress a file

xz

xz filename

compress a file

xz -d filename

decompress a file

431

Linux-

emacs
grep, cat, find, xargs

432

Linux-.bashrc

.bashrc
zsh

433

Linux-tree

tree

ubuntu sudo apt-get install tree

tree

-f

show full path

-L levelNum

specify depth

-P pattern

using wildcard to match file names to limit listing

-d

show dirs only

-r

reverse order

-t

sort output by last modification time

--dirsfirst

list dir before files

--filelimit n

don't go into dir that's more than n files

-F

display file type indicator

-p

show file perm and type

-h

print file size in human readable format

()

434

Linux-tree

-L levelNum

-P

-P '*html' to show only html files and dirs

-r

-t

-F

-p

()

-h

(human-readable)

435

tar gzip bzip2 xz 7zip rar zip .

Summary

1. linux.tar.gz
2. sizetar.xz (xz)
3. zip.zip
4. 7z().7z

targzxz

tar

tar cvf tar_file_name.tar dir_name


tar xvf tar_file_name.tar

c: create
x: eXtract
f:file
v:verbose

tar.tar.gz, tar.bz2, tar.xz


tar xzvf xxx.tar.gz // for tar.gz file
tar xjvf xxx.tar.bz2 // for tar.bz2 file
tar xJvf xz.tar.xz // for tar.xz file

gzip
(tar)

436

compress : gzip filename (filename.tar)


decompress: gzip -d filename.xx.gz (.gz)
gunzip filename, -d

bzip2
.bz2
compress: bzip2 filename
decompress: bzip2 -d filename

xz
.xz

zip
.zip
compress: zip -r new_name.zip dir_name
decompress: unzip filename

7z
7z
compress: 7z a -t7z 7z_file_name.7z dir_name
decompress: 7z e file_name.7z

rar
windows
decompress: 7z e file_name.rar

437

Potrebbero piacerti anche