没有合适的资源?快使用搜索试试~ 我知道了~
Beej's guide to C programming
5星 · 超过95%的资源 需积分: 10 17 下载量 8 浏览量
2009-04-21
21:32:59
上传
评论
收藏 388KB PDF 举报
温馨提示
试读
136页
Beej's guide不知道大家熟悉不熟悉,它有好几个类似的书。都是浅显易懂的,对初学者很有帮助。虽然浅显,但是该讲的东西一点都不会遗漏。关键的关键是,不会像教科书一样故作深沉,也不会像是一些只顾赚钱的书籍那样通篇的代码,却不说关键点。反正我是对它充满了感激之情啊。
资源推荐
资源详情
资源评论
Beej's Guide to C Programming
Brian “Beej” Hall
beej@beej.us
Revision alpha-25
May 17, 2007
Copyright © 2007 Brian “Beej” Hall
ii
Contents
1. Foreward.........................................................................................................................................1
1.1. Audience 1
1.2. Platform and Compiler 1
1.3. Building under Unix 2
1.4. Official Homepage 2
1.5. Email Policy 2
1.6. Mirroring 2
1.7. Note for Translators 3
1.8. Copyright and Distribution 3
2. Programming Building Blocks..................................................................................................... 4
2.1. The Specification 4
2.2. The Implementation 5
2.3. So Much To Do, So Little Time 6
2.4. Hello, World! 7
3. Variables, Expressions, and Statements (Oh My)....................................................................10
3.1. Variables 10
3.2. Operators 11
3.3. Expressions 12
3.4. Statements 12
4. Building Blocks Revisited............................................................................................................17
5. Functions.......................................................................................................................................18
5.1. Passing by Value 20
5.2. Function Prototypes 20
6. Variables, The Sequel..................................................................................................................22
6.1. “Up Scope” 22
6.2. Storage Classes 24
7. Pointers--Cower In Fear!............................................................................................................26
7.1. Memory and Variables 26
7.2. Pointer Types 27
7.3. Dereferencing 28
7.4. Passing Pointers as Parameters 28
8. Structures......................................................................................................................................30
8.1. Pointers to structs 31
8.2. Passing struct pointers to functions 32
9. Arrays............................................................................................................................................34
9.1. Passing arrays to functions 35
Contents
iii
10. Strings..........................................................................................................................................38
11. Dynamic Memory.......................................................................................................................40
11.1. malloc() 40
11.2. free() 41
11.3. realloc() 41
11.4. calloc() 43
12. More Stuff!................................................................................................................................. 44
12.1. Pointer Arithmetic 44
12.2. typedef 45
12.3. enum 46
12.4. More struct declarations 47
12.5. Command Line Arguments 48
12.6. Multidimensional Arrays 50
12.7. Casting and promotion 51
12.8. Incomplete types 52
12.9. void pointers 53
12.10. NULL pointers 54
12.11. More Static 55
12.12. Typical Multifile Projects 56
12.13. The Almighty C Preprocessor 58
12.14. Pointers to pointers 61
12.15. Pointers to Functions 63
12.16. Variable Argument Lists 65
13. Standard I/O Library................................................................................................................69
13.1. fopen() 71
13.2. freopen() 73
13.3. fclose() 75
13.4. printf(), fprintf() 76
13.5. scanf(), fscanf() 81
13.6. gets(), fgets() 84
13.7. getc(), fgetc(), getchar() 86
13.8. puts(), fputs() 88
13.9. putc(), fputc(), putchar() 89
13.10. fseek(), rewind() 90
13.11. ftell() 92
13.12. fgetpos(), fsetpos() 93
13.13. ungetc() 94
13.14. fread() 96
13.15. fwrite() 98
13.16. feof(), ferror(), clearerr() 99
13.17. perror() 100
13.18. remove() 102
13.19. rename() 103
13.20. tmpfile() 104
Contents
iv
13.21. tmpnam() 105
13.22. setbuf(), setvbuf() 107
13.23. fflush() 109
14. String Manipulation.................................................................................................................111
14.1. strlen() 112
14.2. strcmp(), strncmp() 113
14.3. strcat(), strncat() 115
14.4. strchr(), strrchr() 116
14.5. strcpy(), strncpy() 117
14.6. strspn(), strcspn() 118
14.7. strstr() 119
14.8. strtok() 120
15. Mathematics..............................................................................................................................122
15.1. sin(), sinf(), sinl() 124
15.2. cos(), cosf(), cosl() 125
15.3. tan(), tanf(), tanl() 126
15.4. asin(), asinf(), asinl() 127
15.5. acos(), acosf(), acosl() 128
15.6. atan(), atanf(), atanl(), atan2(), atan2f(), atan2l() 129
15.7. sqrt() 130
16. Complex Numbers................................................................................................................... 131
17. Time Library............................................................................................................................132
1
1. Foreward
No point in wasting words here, folks, let's jump straight into the C code:
E((ck?main((z?(stat(M,&t)?P+=a+'{'?0:3:
execv(M,k),a=G,i=P,y=G&255,
sprintf(Q,y/'@'-3?A(*L(V(%d+%d)+%d,0)
And they lived happily ever after. The End.
What's this? You say something's still not clear about this whole C programming language
thing?
Well, to be quite honest, I'm not even sure what the above code does. It's a snippet from one of
the entires in the 2001 International Obfuscated C Code Contest
1
, a wonderful competition wherein
the entrants attempt to write the most unreadable C code possible, with often surprising results.
The bad news is that if you're a beginner in this whole thing, all C code you see looks
obfuscated! The good news is, it's not going to be that way for long.
What we'll try to do over the course of this guide is lead you from complete and utter sheer lost
confusion on to the sort of enlightened bliss that can only be obtained though pure C programming.
Right on.
1.1. Audience
As with most Beej's Guides, this one tries to cater to people who are just starting on the topic.
That's you! If that's not you for whatever reason the best I can hope to provide is some pastey
entertainment for your reading pleasure. The only thing I can reasonably promise is that this guide
won't end on a cliffhanger...or will it?
1.2. Platform and Compiler
I'll try to stick to Good Ol'-Fashioned ANSI C, just like Mom used to bake. Well, for the most
part. Here and there I talk about things that are in subsequent C standards, just to try to keep up to
date.
My compiler of choice is GNU gcc since that's available on most systems, including the Linux
systems on which I work.
Since the code is basically standard, it should build with virtually any C compiler on virtually
any platform. If you're using Windows, run the result in a DOS window. All sample code will be
using the console (that's “text window” for you kids out there), except for the sample code that
doesn't.
There are a lot of compilers out there, and virtually all of them will work for this book. And for
those not in the know, a C++ compiler will compile C most code, so it'll work for the purposes of
this guide. Some of the compilers I am familiar with are the following:
•
GCC
2
: GNU's C compiler, available for almost every platform, and popularly installed on
Unix machines.
•
Digital Mars C/C++
3
: The hackers at Digital Mars have a pretty rippin' C/C++ compiler
for Windows that you can download and use for free, and that will work wonderfully for
all the code presented in this guide. I highly recommend it.
1. http://www.ioccc.org/
剩余135页未读,继续阅读
资源评论
- Ultra_Coder2016-07-07很好的资料,很齐全,谢谢.
DadaLee
- 粉丝: 2
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功