TY - BOOK AU - Kanetkar, Yashavant TI - Let us C SN - 8183331637 U1 - 005.133 PY - 2013/// CY - New Delhi PB - BPB Publications KW - C (Computer program language) KW - Computer programming N1 - Contents I. Getting Started • What is C 2 Getting Started with C ' 4 The C Character Set 5 Constants, Variables and Keywords 5 Types of C Constants y Rules for Constructing integer Constants 7 Rules for Constructing Real Constants 8 Rules for Constructing Character Constants 9 Types of C Variables 10 Rules for Constructing Variable Names 10 C Keywords 11 The First C Program 12 Compilation and Execution Ig Receiving Input 19 C Instructions 91 Type Declaration Instruction 22 Arithmetic Instruction 23 Integer and Float Conversions 27 Type Conversion in Assignments 28 Hierarchy of Operations 30 Associativity of Operators 33 Control Instructions in C 35 ' Summary 3^ Exercise 3^ 2. The Decision Control Structure 47 Decisions! Decisions! 48 The // Statement • 49 The Real Thing 53 Multiple Statements within if 55 The if-else Statement 55 Nested f-else's 59 Forms of if Use of Logical Operators The else //'Clause The ! Operator Hierarchy of Operators Revisited A Word of Caution The Conditional Operators Summary Exercise The Loop Control Structure Loops The while Loop Tips and Traps More Operators The /or Loop Nesting of Loops Multiple Initialisations in the/or Loop The break Statement The continue Statement The do-while Loop The Odd Loop Summary Exercise The Case Control Structure Decisions Using switch The Tips and Traps switch Versus if-else Ladder The goto Keyword Summary Exercise Functions & Pointers What is a Function Why Use Functions Passing Values between Functions 167 Scope Rule of Functions 172 Calling Convention I73 One Dicey Issue I74 Advanced Features of Functions 175 Return Type of Function I77 Call by Value and Call by Reference 178 An Introduction to Pointers 178 PointerNotation I79 Back to Function Calls 186 Conclusions 189 Recursion 190 Recursion and Stack I95 Adding Functions to the Library 198 Summary 201 Exercise 202 6. Data Types kevisited 217 Integers, long and short 218 Integers, signed and unsigned 220 Chars, signed and unsigned 221 Floats and Doubles 223 A Few More Issues... 226 Storage Classes in C 227 Automatic Storage Class 228 Register Storage Class 231 Static Storage Class 232 External Storage Class 235 A Few Subtle Issues 238 Which to Use When 240 Summary 241 Exercise 241 7. The C Preprocessor 249 Features of C Preprocessor 250 Macro Expansion 251 xn Macros with Arguments 255 Macros versus Functions 260 File Inclusion 261 Conditional Compilation ' 263 Directives ^ 267 Miscellaneous Directives 268 (3fe/Directive 268 ^pragma Directive 269 The Build Process 272 Preprocessing 274 Compilation 274 Assembling 274 Linking 276 Loading 277 Summary 279 Exercise 279 8. Arrays What are Arrays 286 A Simple Program Using Array 288 More on Arrays 291 Array Initialization 291 Bounds Checking 292 Passing Array Elements to a Function 293 Pointers and Arrays 295 Passing an Entire Array to a Function 303 The Real Thing 304 Two Dimensional Arrays 306 Initializing a 2-Dimensional Array 307 Memory Map ofa 2-Dimensional Array , 308 Pointers and 2-Dimensional Arrays 309 Pointer to an Array 312 Passing 2-D array to a Function 314 Array of Pointers 317 Three Dimensional Array 319 Summary 321 Xlll Exercise 322 9. Strings 345 What are Strings 346 More about Strings 347 Pointers and Strings 352 Standard Library String Functions 353 strlen() 354 strcpy( ) 356 strcat() 360 strcmp() 361 Two-Dimensional Array of Characters 362 Array of Pointers to Strings 365 Limitation of Array of Pointers to Strings 369 Solution 370 Summary 371 Exercise 372 10. Structures Why Use Structures 382 Declaring a Structure 385 Accessing Structure Elements 388 How Structure Elements are Stored 388 Array of Structures 390 Additional Features of Structures 392 Uses of Structures 402 Summary 403 Exercise 404 11. Console Input/Output 413 Types ofI/O' 414 Console I/O Functions 415 Formatted Console I/O Functions 416 sprintf() and sscanf() Functions 425 Unformatted Console I/O Functions 426 Summary 430 xiv Exercise 12. File Input/Output Data Organization File Operations Opening a File Reading from a File ^ Trouble in Opening a File Closing the File Counting Characters, Tabs, Spaces,... A File-copy Program Writing to a File File Opening Modes String (line) I/O in Files The Awkward Newline Record I/O in Files Text Files and Binary Files Record I/O Revisited Database Management Low Level Disk I/O A Low Level File-copy Program I/O Under Windows Summary Exercise 13. More Issues In Input/Output Using argc and argv Detecting Errors in Reading/Writing Standard I/O Devices I/O Redirection Redirecting the Output Redirecting the Input Both Ways at Once 14. Operations On Bits 505 Bitwise Operators 506 One's Complement Operator 508 Right Shift Operator 510 Left Shift Operator 512 Bitwise AND Operator 517 Bitwise OR Operator 522 Bitwise XOR Operator 523 The showbits() Function 525 Hexadecimal Numbering System 526 Relationship between Binary and Hex 527 Summary 529 Exercise 530 15. Miscellaneous Features 535 Enumerated Data Type 536 Uses ofEnumerated Data Type 537 Are Enums Necessary • 540 Renaming Data Types with typedef 541 Typecasting 543 Bit Fields 545 Pointers to Functions 547 Functions Returning Pointers 550 Functions with Variable Number ofArguments 551 Unions . 555 Union of Structures 561 Utility of Unions 563 The volatile Qualifier ^ 565 Summary 565 Exercise - 566 16. C Under Windows 571 Salient Features of Windows Programming 572 Powerful API Function 572 Hardware Independent Programming 573 Event Driven Programming Model 574 17. The First Windows Program Graphics Under Windows Device Independent Drawing Hello Windows Drawing Shapes Types of Pens Types of Brushes Freehand Drawing, the Paintbrush Style Capturing the Mouse Device Context, a Closer Look Displaying a Bitmap Animation at Work WM_CREATE and OnCreate() 616 WM_TIMER and OnTimer() 616 A Few More Points... Windows, the Endless World... 619 Summary 619 Exercise 621 Network & Internet Programming 623 Network Communication 624 Packets and Sockets 626 Before We Start... 627 Protocols 627 IP Addresses 628 Port Numbers 629 Byte Ordering 630 Getting Started... 631 What's The Time Now 634 Creation of Socket 638 Sending Data to a Time Server 639 Receiving Date and Time 640 Communicating with Whois Server 641 Give Me the Home Page 645 Sending and Receiving Emails 647 Two-Way Communication 659 Summary 666 Exercise 18. C Under Linux 669 What is Linux 670 C Programming Under Linux 671 The 'Hello Linux' Program 672 Processes 674 Parent and Child Processes 675 More Processes 679 Zombies and Orphans 681 One Interesting Fact 684 Summary 684 Exercise 685 19. More Linux Programming 687 Communication using Signals 688 Handling Multiple Signals 691 Registering a Common Handler 693 Blocking Signals 695 Event Driven Programming 698 Where Do You Go From Here 703 ER -