A to Z of C - Beta (v0.0.12)

The evolving non-profit book on C/DOS/Turbo C programming

Alert

This book "A to Z of C" is compiled and written by simple guys who are not experts and who are not native English speakers. And so, this book might have both grammatical and technical errors.

This is the non-profit project and this release is a beta version. If you find any bugs please report that bug to us! You may also contact us, if your name or material is misused or not properly credited. We'll try to fix the bugs in periodic basis.

Constructive criticism and valuable suggestions are always welcome. Post them via contact page. If you know any other means of releasing the material so that the Internet experts can easily tune A to Z of C (open-source?), please let us know!

The book is released in PDF format. For best results, download/view the PDF format instead of converting it to HTML.

Some user has made the entire book available in a single PDF file zipped [1.92 MB] for easy downloading. It is downloadable at 4shared.com

 
About | Revision History | History | Known Bugs | Download Problems | HTML Version | Bug Report | Errata | E-group/Mailing List | CD | Links | Contact Us! | Contents | Companion Links
 

A to Z of C

 

Part I: ANSI C
Part II: DOS Programming
Part III: Advanced Graphics Programming
Part IV: Advanced Programming
Part V: Mathematics & C
Part VI: Algorithms & C
Part VII: Illegal Codes
Part VIII: Next Step
Part IX: Smart Dictionary
Part X: Postlude

About

A to Z of C is the book on C/DOS programming. This is the non-profit project by my friend K. Joseph Wesley and myself (R. Rajesh Jeba Anbiah) intended to provide the cheapest and best C/DOS programming book to Indian intellectuals who cannot afford to buy costlier books.

Throughout the world many people have contributed to this work by providing their valuable articles, source codes, suggestions, etc. The notable experts are Dr. Dennis M. Ritchie, Dr. Ralf Brown, Mr. Alexander Russell, Dr. Cristina Cifuentes and so many.

We compiled and wrote this book from April 2000 to November 2001 (more than 1½ years) while we were studying MCA. When we finished this book, no publishers were ready to accept this non-profit work. Also, we understood that the book has lots of grammatical errors. And so, we have decided to publish this book online so that the book can be tuned by Internet experts. But, unfortunately we couldn't immediately publish this book as we're running out of resources. Finally, this book in PDF format is released here at this Freeservers site!

You may tune up this book by reporting bugs and or by publishing this book at cheaper price so that many Indian guys will be benefitted.

Revision History

v0.0.12 April 13, 2008 (Current)
    • Adobe replaced with PDF download for HTML conversion service
    • Credits for iit-b and Code.box.sk
    • Note about single zip of entire book in the top alert box
v0.0.11 January 3, 2005
    • Companion links added
v0.0.10 August 9, 2004
    • Webpage optimized for cross-browser functionalities
v0.0.9 January 21, 2004
    • CD section added
v0.0.8 January 12, 2004
    • Mailing list added
    • Many thanks to Adrian Cunnelly for informing new version of his Netware C Library.
v0.0.7 November 24, 2003
    • Download problem seems to be rectified. Special thanks to Son Gokou for reporting such strange problem
    • PDF files have been re-uploaded because of strange problem with Freeservers
v0.0.6 November 21, 2003
    • Site caption added
v0.0.5 November 20, 2003
    • Download Problems section added
    • Source code of PR (utility to print non-printable characters) is made available to download
v0.0.4 November 10, 2003
    • Revision History section added
    • Source code of EZOS_86 (v2) is made available to download. Special thanks to Scott A. Christensen, creator of EZOS_86 for sending and informing the new version
    • Both Google cache and Adobe as PDF conversion services
    • Link to Joseph Wesley's homepage
    • Source codes section is restructured to track downloads
    • Also, source codes related to VB Controls, Fire, PC-PILOT, BIOS, and CMOS are added for spirit
v0.0.3 November 1, 2003
    • PDF files distilled with Distiller for better clarity
    • Titles of all PDF files have been fixed
    • Big PDF files have been splitted and made available
    • Source code of Scribble is made available to download
v0.0.2 August 14, 2003
    • HTML conversion service is changed from Adobe to Google's cache
v0.0.1 August 1, 2003
    • Initial release

History

Yet to write.

Known Bugs

This free site has file size limitations and bandwidth limitations. And so, the contents of CD are not available here. Word to PDF conversion is also bit poor. Also, see Download Problems

Download Problems

To download the book (PDF format) scroll down to Contents section righ-click on the chapter titles and choose "Save Target As..." It may not work if you're directed from other sites (i.e., if REFERER header is set) as the free site providers don't like linking the contents from other sites. If you face "permission denied" or similar errors, open a new browser session and re-try.

To download the source codes (ZIP), just left-click on the link or choose "Open in New Window" in right-click——"Save Target As..." option won't work.

HTML Version

This book is available only in PDF format. If you want to see the HTML version, you may use PDF download conversion service or Google's cached HTML version by clicking the following button. For best results, we suggest viewing PDF format.

Courtesy: PDF Download and Google

Bug Report

To report any grammatical or technical bug visit here

Errata

The book has so many bugs. To view the reported/acknowledged bugs visit here

E-group/Mailing List
CD

Most of the mails we receive are related to the CD, like where and how to get it. But, at present, we're not distributing the CD. We have added Companion Links section; where you can find related files and tutorials—this may be considered as an alternative to CD. The total file size of CD goes up to 100 MB and it's eventually impossible to make it online.

Links

Please refer Companion Links

Contact Us!

You may send any info or mails via this page

Many thanks to all the people who sent us bug reports and loving mails. After some struggle we--the authors are well placed. Now, it's not the money, but the time that affects this project. Anyway, keep on sending mails and bug reports; I'll try to update the book now and then (but please don't expect a personal reply).
Thanks for all your support and love.
Our special thanks goes to the people who made this project quite popular than what we expected:
IIT Bangalore (now links are moved, but found here and there)
Code.box.sk

--R. Rajesh Jeba Anbiah, April 13, 2008


Contents

Part I: ANSI C | Part II: DOS Programming
Part III: Advanced Graphics Programming | Part IV: Advanced Programming
Part V: Mathematics & C | Part VI: Algorithms & C | Part VII: Illegal Codes | Part VIII: Next Step
Part IX: Smart Dictionary | Part X: Postlude

1. First Chapter

1.1 Acknowledgement
1.2 Book Organization
1.3 FAQ about A to Z of C

2. Birth of C
3. Coding Style

3.1 Indian Hill Style
3.2 Hungarian Coding Style
3.3 WAR (Wesley And Rajesh) Coding Style

Part I
ANSI C

4. ANSI C - Prelude

4.1 Myth & Mistakes
4.2 Tips for better Programming
    4.2.1 Coding Style
    4.2.2 Boolean Variables
    4.2.3 How to code better?

5. main( ) and Mistakes

5.1 What main( ) returns?
5.2 Arguments of main( )
5.3 exit( )

6. Undefined

6.1 Example
6.2 Frequently Asked Undefined Questions

7. The Magic XOR

7.1 Swap Macro
7.2 Flip and Flop
7.3 Crypting with XOR

8. String Function

8.1 strlen( )
8.2 strcpy( )
8.3 strcat( )
8.4 strcmp( )

9. Recursion

9.1 Factorial
9.2 Fibonacci
9.3 GCD
9.4 Power
9.5 Reverse Printing
9.6 Decimal to binary conversion
9.7 Decimal to hexadecimal conversion
9.8 Printing a decimal in words

10. Interesting Programs

10.1 Power of 2
10.2 Prime Numbers
10.3 Roman Letters   [convert Arabic numerals to Roman numerals]
10.4 Day of Week
10.5 Calendar
10.6 Memory-Swap
10.7 Block Structure
    10.7.1 Swap macro using Block Structure
10.8 Printf with %b

11. Program that Outputs the same

11.1 Self-replicating program #1
11.2 Self-replicating program #2
11.3 Self-replicating program #3

12. Pointers

12.1 Memory Overwrite
12.2 Array/Buffer Overflow
12.3 Memory Leak
12.4 Multidimensional array implementation
    12.4.1 Version 1
    12.4.2 Version 2
    12.4.3 Version 3
    12.4.4 Version 4
12.5 Linked List

13. Code Obfuscation

13.1 Where to contest?
13.2 Guidelines
13.3 Real Code
    13.3.1 Wherami
    13.3.2 Note

Part II
DOS Programming

14. DOS Secrets

14.1 Prelude
    14.1.1 BIOS
    14.1.2 Bootstrap Program
    14.1.3 Boot Sector
14.2 Memory Layout
    14.2.1 Upper Memory Area (UMA)
14.3 Segment Address
14.4 Extended Memory
14.5 Limitations of DOS

15. Traits of Turbo C

15.1 Features of TC++3.0
15.2 Configure your TC++3.0
15.3 IDE basics
15.4 Useful Utilities
    15.4.1 BASM
    15.4.2 TASM
    15.4.3 TLINK
    15.4.4 TLIB
    15.4.5 MAKE
    15.4.6 TCC
15.5 main( )
    15.5.1 int main( ) or void main( ) ?
15.6 Preprocessor
15.7 Header file
15.8 Pragma
    15.8.1 Example 1
    15.8.2 Example 2
15.9 Creating library file
15.10 Creating a project file
15.11 Turbo C keywords
15.12 Bugs & Remedy
    15.12.1 system( )
    15.12.2 delay( )
    15.12.3 Floating point formats not linked
    15.12.4 Null pointer assignment

16. Mating Assembly with C

16.1 Inline Assembly
    16.1.1 Example 1
    16.1.2 Example 2
    16.1.3 Usual Errors
16.2 Calling Assembly routines from C
    16.2.1 C’s calling convention
    16.2.2 C’s naming convention
    16.2.3 Example 1
    16.2.4 Example 2
16.3 Creating library file out of assembly language module

17. Processor

17.1 Processors
17.2 Processor Modes
    17.2.1 Real Mode
    17.2.2 Protected Mode
    17.2.3 Virtual Real Mode
17.3 Processor Type
    17.3.1 C program to find processor type
    17.3.2 Assembly routine to find processor type
    17.3.3 Another Assembly routine

18. File Format

18.1 Example

19. Interrupt Programming

19.1 Logical outline of interrupt routine
19.2 Interrupt Classification
19.3 Programming with interrupts
    19.3.1 Inline Assembly Style
    19.3.2 Pure Assembly Style
    19.3.3 geninterrupt( ) style
    19.3.4 int86( ) style
    19.3.5 intr( ) style
    19.3.6 Benchmarking
19.4 Myth & Mistakes

20. Programming Video RAM

20.1 Memory map
20.2 Programming the video RAM
    20.2.1 Color Text Mode
    20.2.2 Monochrome Text Mode
    20.2.3 Graphics Mode

21. Programming Ports

21.1 Why use ports?
21.2 Port vs. memory
21.3 Usual Problems
21.4 Programming ports with Turbo C
21.5 Example

22. Programming the keys

22.1 Secrets
    22.1.1 Keyboard controller
    22.1.2 Keyboard Buffer
    22.1.3 Keyboard status
    22.1.4 Keyboard Interrupt
22.2 Activating the keys without pressing it!
    22.2.1 Stuff keys using BIOS interrupt
    22.2.2 Stuff keys using keyboard buffer
22.3 Multiple key Input

23. Sound Programming with PC Speaker

23.1 Introduction
23.2 Programming PIT
23.3 Producing Sound
23.4 Notes & Frequencies
23.5 Piano Keys and Frequencies
23.6 Piano Program

24. Sound Programming with sound card

24.1 Idea

25. Mouse Programming

25.1 Mouse Interrupts
25.2 Useful Mouse functions
    25.2.1 Mouselib.h
    25.2.2 Mouselib.c
    25.2.3 Mouselib.lib
25.3 Mouse Function 0Ch
25.4 Request Mode or Event Mode?

26. Playing with Pointers

26.1 Rebooting with pointers
26.2 Identifying machine model and BIOS date

27. TSR Programming

27.1 DOS’s non-reentrancy Problem
27.2 Switching Programs
27.3 DOS Busy Flag
27.4 BIOS Functions
27.5 Popping up TSR
27.6 IBM’s Interrupt-Sharing Protocol
27.7 Rules for TSR Programming
27.8 TSR Template
27.9 PC-PILOT
Source code (with EXE)   [zip, 48.9 KB]

Part III
Advanced Graphics Programming

28. Graphics with BGI

28.1 Common Mistake!
28.2 More Colors
28.3 Jordan Hargraphix Software’s SuperVGA/Tweak BGI drivers
28.4 Jordan Hargraphix Software’s HGXMOUSE TSR

29. VB Controls

29.1 Paintbrush
    29.1.1 Restricting Mouse Pointer
    29.1.2 Hiding/Showing Mouse Pointer
    29.1.3 Avoiding Flickering of Mouse Pointer
    29.1.4 Using setwritemode( ) function
29.2 Note
Source code (with EXE)   [zip, 33.8 KB]

30. Scribble   [CHR file creator/BGI font file creator]

30.1 Prelude
30.2 Storing Fonts
30.3 Scribble screenshots
30.4 Mouselib.lib
    30.4.1 Mouselib.h
    30.4.2 Mouselib.c
    30.4.3 Mouselib.lib
30.5 Scribble.h
30.6 Scribble.c
30.7 Scribble.prj
Source code (with EXE)   [zip, 80.7 KB]

31. Creating GIF files

31.1 Important Notice
31.2 GIFSAVE
31.3 Gifsave.h
31.4 Gifsave.c
31.5 Example usage of GIFSAVE

32. Mode 13h Programming

32.1 Mode 13h
    32.1.1 Palette Register
    32.1.2 Vertical Retrace
32.2 Optimization Note

33. Reading BMP Files

33.1 Programs

34. Fire

34.1 Extracting Palette
    34.1.1 PAL Utility
    34.1.2 Using PAL
34.2 Fire Program
Source code (with EXE)   [zip, 24.2 KB]

35. VESA Programming

35.1 Secrets
35.2 Program

36. 3D Graphics

36.1 Perspective Projection
36.2 3D Rectangle

37. Fractal

37.1 Prelude
37.2 Program

Part IV
Advanced Programming

38. Game Programming

38.1 Graphics Mode
38.2 Logic
38.3 Alexander Russell’s Guide

39. Interfacing

39.1 Interfacing LCD with parallel port
    39.1.1 Circuit Diagrams
    39.1.2 Logic
    39.1.3 Program

40. Embedded Systems

40.1 PROM
40.2 EPROM
40.3 EEPROM
40.4 Programming for Embedded Systems
40.5 Locate utility
40.6 ROMable Code
40.7 Applications

41. Writing BIOS

41.1 BIOS Code
41.2 Flash BIOS
41.3 Uniflash
Source code (ASM)   [zip, 35.3 KB]

42. Programming CMOS RAM

42.1 Viewing contents of CMOS RAM
    42.1.1 Logic
    42.1.2 Code
42.2 Diagnose CMOS RAM
    42.2.1 Logic
    42.2.2 Code
Source code   [zip, 5.05 KB]

43. Device Driver Programming

43.1 Secrets
43.2 Types of MS DOS device drivers
    43.2.1 Character device drivers
    43.2.2 Block device drivers
43.3 Writing our own device driver
43.4 BUF160
    43.4.1 Source code
    43.4.2 Compiling BUF160
    43.4.3 Installing BUF160
43.5 BGI Driver

44. Network Programming

44.1 Novell Netware
    44.1.1 Network Library
    44.1.2 Example – Toserver.c
    44.1.3 Example – Ulist.c
44.2 Windows NT
Note: Adrian Cunnelly, author of Netware C Library has informed us about the new/free/better version. File can be downloaded here. [zip, 507 KB]

45. Writing Browser

45.1 TCP/IP Programming
    45.1.1 WATTCP
45.2 Programming Browser

46. Programming Protocols

46.1 Basic Idea!
46.2 Developing a new Protocol

47. Writing Operating System

47.1 EZOS_86
    47.1.1 Notes
    47.1.2 Kernel Source Code
47.2 Good Luck!
Source code (version 2)   [zip, 16.4 KB]

48. Developing a new language / writing compiler

48.1 Secrets
48.2 Writing a compiler
    48.2.1 Compiler
    48.2.2 Compiler Secrets
48.3 Compiler-writing tools
    48.3.1 lex
    48.3.2 YACC
    48.3.3 Creating Compiler with lex & YACC

49. Writing YACC

49.1 Prelude
49.2 BYACC
    49.2.1 Brief History
    49.2.2 Source code
    49.2.3 Compiling BYACC

50. Developing a Database Package

50.1 Basic Idea
50.2 File format for DBF file
50.3 Security

51. Decompilation / EXE to C

51.1 Basic Idea
51.2 DCC
    51.2.1 Disclaimer
    51.2.2 Notice
    51.2.3 DCC Facts
    51.2.4 Example of Decompilation

52. Writing Disassembler

52.1 Prelude
52.2 Secrets
52.3 2asm
    52.3.1 Table.c
    52.3.2 Disasm.c
    52.3.3 2asm.prj

53. Printer Programming

53.1 Types of Printers
    53.1.1 Dot Matrix Printers
    53.1.2 Inkjet Printers
    53.1.3 Laser Printers
53.2 Printer Languages
    53.2.1 Page Description Language
    53.2.2 Escape Codes
53.3 Printing non-printable characters
    53.3.1 Epson Extended Character Set
    53.3.2 Graphics Mode
    53.3.3 Font Map
    53.3.4 Optimization Tip
    53.3.5 Program
Source code (with EXE)   [zip, 14.7 KB]

Part V
Mathematics & C

54. Implementing Math Functions

54.1 Range reduction and Chebychev polynomial approximation
54.2 CORDIC Method

55. Differentiation

55.1 Program

56. Integration

56.1 Program
56.2 Numerical Analysis

57. PI

57.1 π
57.2 Program

58. Easter Day

58.1 Oudin’s Algorithm
58.2 Easter Day Program

Part VI
Algorithms & C

59. CORDIC

59.1 Birth of CORDIC
59.2 Advantages
59.3 Principle
59.4 Algorithm
59.5 Program

60. LZW (Lempel Ziv Welch)

60.1 Brief History
60.2 Principle behind LZW
60.3 LZW Compression
    60.3.1 Compression Algorithm
    60.3.2 Example
60.4 LZW Decompression
    60.4.1 Decompression Algorithm
    60.4.2 Example

61. Backtracking Algorithms

61.1 Recursive Maze Algorithm
61.2 Maze
61.3 Principle of Maze
61.4 Program

Part VII
Illegal Codes

62. Overcome BIOS Security

62.1 Bypass System password
    62.1.1 Default master password
    62.1.2 Hardware techniques (clearing CMOS RAM)
62.2 Bypass Setup password
    62.2.1 Default master password
    62.2.2 Program

63. Cracking Techniques

63.1 Brute force technique
63.2 Dictionary attack

64. Cracking ZIP file’s Password

64.1 Cracking ZIP passwords
64.2 CrackIt
    64.2.1 Logic
    64.2.2 Code

65. Network Passwords

65.1 Novell Netware
    65.1.1 Fake Prompts
    65.1.2 TSR program
    65.1.3 Brute force Cracking
    65.1.4 Cracking from password file
65.2 Windows NT

66. Cracking File Format

66.1 DEBUG
66.2 Finding out Signature
66.3 Algorithms
66.4 Standard Format

67. Virus Programming

67.1 Logic
67.2 TSR viruses
67.3 Windows viruses
67.4 Anti-Viruses

Part VIII
Next Step

68. 32-bit Compiler

68.1 16-bit Compiler
68.2 32-bit Compiler (DJGPP)
    68.2.1 Allegro

69. Descendents of C

69.1 C++
69.2 Java
69.3 C#
69.4 D

Part IX
Smart Dictionary

70. Slang & Jargons
71. Ralf Brown’s Interrupt List 1 of 3, 2 of 3, 3 of 3

71.1 Notations
71.2 Interrupt List
    71.2.1 Overview
    71.2.2 Listing
71.3 Port listing
    71.3.1 Notations
    71.3.2 Listing
71.4 Memory map
71.5 Other resources

72. File format Collections 1 of 2, 2 of 2

72.1 File Formats Encyclopedia
72.2 ARJ
    72.2.1 Glimpse
    72.2.2 Official documentation
72.3 BMP
72.4 CHR
72.5 COM
72.6 CUR
72.7 DBF (General Format of .dbf files in Xbase languages)
72.8 EXE
    72.8.1 Old EXE format (EXE MZ)
    72.8.2 New EXE format (EXE NE)
72.9 GIF
72.10 ICO
72.11 JPEG
72.12 LZH
72.13 MIDI
72.14 PCX
72.15 PIF
72.16 RTF
72.17 SCR
72.18 WAV
72.19 ZIP
72.20 ZOO

73. Printer Escape Codes
74. ASCII Table
75. Scan Code

Part X
Postlude

76. Test in C

76.1 ANSI C
76.2 Turbo C / DOS Programming
76.3 Windows

77. C Resources

77.1 Magazine
77.2 Books
77.3 Jobs
77.4 Associations
77.5 Websites

78. Between You and Me

78.1 Our Education System
78.2 Software Industry
    78.2.1 Myths & Facts
78.3 Mother tongue
78.4 Next generation people
    78.4.1 Shareware
    78.4.2 GPL
78.5 Heal the World

79. Last Chapter

79.1 Web page – GuideMe.ITgo.com
79.2 Errata
79.3 Contact Info
79.4 Final Greetings

Contents of CD
Index

Companion Links

1. First Chapter
2. Birth of C
3. Coding Style

Part I
ANSI C

4. ANSI C - Prelude
5. main( ) and Mistakes
6. Undefined
7. The Magic XOR
8. String Function
9. Recursion
10. Interesting Programs
11. Program that Outputs the same
12. Pointers
13. Code Obfuscation

Part II
DOS Programming

14. DOS Secrets
15. Traits of Turbo C
16. Mating Assembly with C
17. Processor
18. File Format

(See #72)

19. Interrupt Programming
20. Programming Video RAM
21. Programming Ports
22. Programming the keys
23. Sound Programming with PC Speaker
24. Sound Programming with sound card
25. Mouse Programming
26. Playing with Pointers
27. TSR Programming

Part III
Advanced Graphics Programming

28. Graphics with BGI
29. VB Controls
30. Scribble   [CHR file creator/BGI font file creator]
31. Creating GIF files
32. Mode 13h Programming
33. Reading BMP Files
34. Fire
35. VESA Programming
36. 3D Graphics
37. Fractal

Part IV
Advanced Programming

38. Game Programming
39. Interfacing
40. Embedded Systems
41. Writing BIOS
42. Programming CMOS RAM
43. Device Driver Programming
44. Network Programming
45. Writing Browser
46. Programming Protocols
47. Writing Operating System
48. Developing a new language / writing compiler
49. Writing YACC
50. Developing a Database Package
51. Decompilation / EXE to C
52. Writing Disassembler
53. Printer Programming

Part V
Mathematics & C

54. Implementing Math Functions
55. Differentiation
56. Integration
57. PI
58. Easter Day

Part VI
Algorithms & C

59. CORDIC
60. LZW (Lempel Ziv Welch)
61. Backtracking Algorithms

Part VII
Illegal Codes

62. Overcome BIOS Security
63. Cracking Techniques
64. Cracking ZIP file’s Password
65. Network Passwords
66. Cracking File Format
67. Virus Programming

Part VIII
Next Step

68. 32-bit Compiler
69. Descendents of C

Part IX
Smart Dictionary

70. Slang & Jargons
71. Ralf Brown’s Interrupt List
72. File format Collections
73. Printer Escape Codes
74. ASCII Table
75. Scan Code

Part X
Postlude

76. Test in C
77. C Resources
78. Between You and Me
79. Last Chapter
Contents of CD
Index

Launched: August 1, 2003
Last Updated: April 13, 2008
Copyright © 2000-2008 R. Rajesh Jeba Anbiah & K. Joseph Wesley
All Rights Reserved.
238981

drupal analytics
. .