Share E-Book
Scan to open this page

Scan with your phone to open this page

AuthorAgus Kurniawan

This book help you how to get started with C programming. This book provides many code samples for illustration. The following is highlight topics: * Development Environment * Basic C Programming Language * Array and Pointer * Functions * I/O Operations * String Operations * Building C Library * Threading * Database Programming * Socket Programming This book uses GNU GCC compiler for C programming.

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
# Learning C By Example — Reading Guide ## 【One-Line Pitch】 A hands-on, code-first introduction to C programming that walks beginners from compiler setup through threading, databases, and socket programming — ideal for self-learners who want to see working examples rather than lengthy theory. ## 【Book Arc】 - **Opening (~0%–6%)**: Environment setup across Linux, Windows, and Mac, including GCC installation, editor choices, and the classic Hello World — establishes the compile-and-run workflow used throughout. - **Early (~6%–18%)**: Core language fundamentals — variables, arithmetic, logical operators, decision-making with if/switch, loops, structs, and arrays — building a solid syntax foundation. - **Early (~18%–29%)**: Pointer concepts and dynamic memory allocation, followed by function creation, array parameters, and pointer-based function arguments like swap() — the conceptual heart of C. - **Middle (~29%–41%)**: I/O operations including safe input handling with fgets(), string manipulation with strcat() and strlen(), and building reusable C libraries (static and shared). - **Middle (~41%–59%)**: Threading with pthreads — creating threads, obtaining thread IDs, termination strategies, joining, mutex synchronization, and condition variables for signaling. - **Late (~59%–100%)**: Database programming and socket communication (server/client models) — applying earlier concepts to real-world system programming scenarios. ## 【Key Takeaways】 - **Environment setup is the first hurdle** (Early): The book provides platform-specific GCC installation steps for Linux, Windows (Cygwin), and Mac (Xcode), plus editor recommendations — get this right and everything else flows smoothly. - **Semicolons and type discipline matter** (Early): Every statement ends with `;`, and assigning incompatible types (like a string to an int) triggers compiler warnings — the book uses these errors as teaching moments. - **Pointers are memory addresses with power** (Early): Using `&` to get addresses and `*` to dereference, you can build dynamic arrays and pass values by reference — essential for understanding C's memory model. - **Functions with array parameters need explicit sizes** (Early): Unlike higher-level languages, C functions must receive array length as a separate argument, as shown in the mean() calculation example. - **gets() is unsafe — use fgets()** (Middle): The book explicitly demonstrates the danger of gets() and shows fgets() with length limits as the safer alternative for reading text input. - **Building libraries requires header files** (Middle): Creating a static library involves compiling source to object files, creating a header with extern declarations, and linking with `-I` and `-L` flags — a practical introduction to code reuse. - **Thread synchronization prevents race conditions** (Middle): Mutex locks protect shared variables like total_finished_jobs, while condition variables provide signaling and broadcasting mechanisms for more complex coordination. ## 【Reading Tips】 - **Skim the environment setup** (~0%–6%) if you already have GCC working — just note the compile commands (`gcc -o output source.c`) used consistently throughout. - **Deep-read the pointer and function chapters** (~18%–29%) — these are the conceptual foundation for everything later, especially the swap() example and dynamic array implementation. - **Pay attention to the library chapter** (~35%–41%) — the distinction between static (.a) and shared (.so) libraries is practical knowledge you'll reuse in real projects. - **The threading chapter is dense** (~41%–59%) — work through the mutex and condition variable examples slowly, as they demonstrate patterns you'll encounter in system programming. - **Each chapter follows the same pattern**: code sample → save to file → compile → run → observe output. Replicate this workflow yourself rather than just reading. ## 【Coverage Limits】 This guide covers the first ~59% of the book in detail (through threading). The database programming and socket programming chapters appear in the table of contents but their content is not covered in the available excerpts. ##
Page 20
re is the syntax rule: syntax_code; 2.3 Assigning Variables Variable that you already declare can be assigned by a value. It can done using the equals sign (...
View in text
Excerpt 2
matrix[i][j] = i+j; } } // display data for(i=0;i<3;i++){ for(j=0;j<5;j++){ printf("%d ",matrix[i][j]); } printf("\n"); } return 0; } Save this. Then, try to...
View in text
Excerpt 3
string. You can use strcat() function from string.h header. For illustration, create a file, called stringdemo.c, and write the following code. #include <std...
View in text
Excerpt 4
} printf("\r\n"); } int main(int argc, char* argv[]) { pthread_t thread; int ret; errno = 0; int n = 10; ret = pthread_create (&thread, NULL, perform, &n); i...
View in text
Excerpt 5
nsumer. Let’s start to create a file, called condvariable.c. Firstly we define headers and global variables. #include <stdio.h> #include <pthread.h> #include...
View in text
Excerpt 6
ts.hour = now_struct->tm_hour; ts.minute = now_struct->tm_min; ts.second = now_struct->tm_sec; printf("executing data %d…\r\n",i); if (mysql_stmt_execute(stm...
View in text
Excerpt 7
d = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen); 44 if (newsockfd < 0) 45 { 46 printf("\n accept() failed with error [%s]\n",strerror(errno)); 47...
View in text
Excerpt 8
intf("\n read() failed with error [%s]\n",strerror(errno)); 58 return -1; 59 } 60 printf("Received message: %s\n",buffer); 61 62 // write data 63 sz = write(...
View in text
Tags
AI categories
Programming LanguageBackend
Publisher: PE Press
Publish Year: 2015
Language: English
Pages: 129
File Format: PDF
File Size: 4.0 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…