Table of Contents for
Intermediate C Programming

Version ebook / Retour

Cover image for bash Cookbook, 2nd Edition Intermediate C Programming by Yung-Hsiang Lu Published by CRC Press, 2015
  1. Front Cover
  2. Contents (1/2)
  3. Contents (2/2)
  4. List of Figures (1/2)
  5. List of Figures (2/2)
  6. List of Tables
  7. Foreword
  8. Preface
  9. Author, Reviewers, and Artist
  10. Rules in Software Development
  11. Source Code
  12. I. Computer Storage: Memory and File
  13. 1. Program Execution (1/2)
  14. 1. Program Execution (2/2)
  15. 2. Stack Memory (1/5)
  16. 2. Stack Memory (2/5)
  17. 2. Stack Memory (3/5)
  18. 2. Stack Memory (4/5)
  19. 2. Stack Memory (5/5)
  20. 3. Prevent, Detect, and Remove Bugs (1/2)
  21. 3. Prevent, Detect, and Remove Bugs (2/2)
  22. 4. Pointers (1/6)
  23. 4. Pointers (2/6)
  24. 4. Pointers (3/6)
  25. 4. Pointers (4/6)
  26. 4. Pointers (5/6)
  27. 4. Pointers (6/6)
  28. 5. Writing and Testing Programs (1/4)
  29. 5. Writing and Testing Programs (2/4)
  30. 5. Writing and Testing Programs (3/4)
  31. 5. Writing and Testing Programs (4/4)
  32. 6. Strings (1/3)
  33. 6. Strings (2/3)
  34. 6. Strings (3/3)
  35. 7. Programming Problems and Debugging (1/4)
  36. 7. Programming Problems and Debugging (2/4)
  37. 7. Programming Problems and Debugging (3/4)
  38. 7. Programming Problems and Debugging (4/4)
  39. 8. Heap Memory (1/3)
  40. 8. Heap Memory (2/3)
  41. 8. Heap Memory (3/3)
  42. 9. Programming Problems Using Heap Memory (1/4)
  43. 9. Programming Problems Using Heap Memory (2/4)
  44. 9. Programming Problems Using Heap Memory (3/4)
  45. 9. Programming Problems Using Heap Memory (4/4)
  46. 10. Reading and Writing Files (1/3)
  47. 10. Reading and Writing Files (2/3)
  48. 10. Reading and Writing Files (3/3)
  49. 11. Programming Problems Using File (1/2)
  50. 11. Programming Problems Using File (2/2)
  51. II. Recursion
  52. 12. Recursion (1/4)
  53. 12. Recursion (2/4)
  54. 12. Recursion (3/4)
  55. 12. Recursion (4/4)
  56. 13. Recursive C Functions (1/4)
  57. 13. Recursive C Functions (2/4)
  58. 13. Recursive C Functions (3/4)
  59. 13. Recursive C Functions (4/4)
  60. 14. Integer Partition (1/5)
  61. 14. Integer Partition (2/5)
  62. 14. Integer Partition (3/5)
  63. 14. Integer Partition (4/5)
  64. 14. Integer Partition (5/5)
  65. 15. Programming Problems Using Recursion (1/5)
  66. 15. Programming Problems Using Recursion (2/5)
  67. 15. Programming Problems Using Recursion (3/5)
  68. 15. Programming Problems Using Recursion (4/5)
  69. 15. Programming Problems Using Recursion (5/5)
  70. III. Structure
  71. 16. Programmer-Defined Data Types (1/6)
  72. 16. Programmer-Defined Data Types (2/6)
  73. 16. Programmer-Defined Data Types (3/6)
  74. 16. Programmer-Defined Data Types (4/6)
  75. 16. Programmer-Defined Data Types (5/6)
  76. 16. Programmer-Defined Data Types (6/6)
  77. 17. Programming Problems Using Structure (1/4)
  78. 17. Programming Problems Using Structure (2/4)
  79. 17. Programming Problems Using Structure (3/4)
  80. 17. Programming Problems Using Structure (4/4)
  81. 18. Linked Lists (1/3)
  82. 18. Linked Lists (2/3)
  83. 18. Linked Lists (3/3)
  84. 19. Programming Problems Using Linked List (1/2)
  85. 19. Programming Problems Using Linked List (2/2)
  86. 20. Binary Search Trees (1/4)
  87. 20. Binary Search Trees (2/4)
  88. 20. Binary Search Trees (3/4)
  89. 20. Binary Search Trees (4/4)
  90. 21. Parallel Programming Using Threads (1/5)
  91. 21. Parallel Programming Using Threads (2/5)
  92. 21. Parallel Programming Using Threads (3/5)
  93. 21. Parallel Programming Using Threads (4/5)
  94. 21. Parallel Programming Using Threads (5/5)
  95. IV. Applications
  96. 22. Finding the Exit of a Maze (1/5)
  97. 22. Finding the Exit of a Maze (2/5)
  98. 22. Finding the Exit of a Maze (3/5)
  99. 22. Finding the Exit of a Maze (4/5)
  100. 22. Finding the Exit of a Maze (5/5)
  101. 23. Image Processing (1/3)
  102. 23. Image Processing (2/3)
  103. 23. Image Processing (3/3)
  104. 24. Huffman Compression (1/10)
  105. 24. Huffman Compression (2/10)
  106. 24. Huffman Compression (3/10)
  107. 24. Huffman Compression (4/10)
  108. 24. Huffman Compression (5/10)
  109. 24. Huffman Compression (6/10)
  110. 24. Huffman Compression (7/10)
  111. 24. Huffman Compression (8/10)
  112. 24. Huffman Compression (9/10)
  113. 24. Huffman Compression (10/10)
  114. A. Linux
  115. B. Version Control
  116. C. Integrated Development Environments (IDE) (1/3)
  117. C. Integrated Development Environments (IDE) (2/3)
  118. C. Integrated Development Environments (IDE) (3/3)
440 Intermediate C Programming
freque ncies [ ind ]. freq );74
ListNode * ln = L istNod e_crea te ( tn) ;75
head = List_i nsert ( head , ln , SORTED ) ;76
ind ++;77
}78
return head ;79
}80
void List_pri n t ( L i stNode * head )81
{82
i f ( head == NULL )83
{84
return ;85
}86
Tree_pr i nt ( head -> tnptr , 0) ;87
List_pr i nt ( head -> next );88
}89
// utility .h1
#i f n d e f UTILITY_H2
#d ef in e UTILITY_ H3
#in clude < stdio .h >4
// write one bit to a file5
6
// whichbi t indicat e s which bit this is written to (0 means7
// leftmost , 7 means right m ost )8
// curbyte is the c u r rent byte9
//10
// if whichbit is zero , curbyte is reset and bit is put11
// to the leftmost bit12
//13
// when which bit r e a ches 7, this byte is written to the14
// file and whichbit is reset15
//16
// the functi o n returns 1 if a byte is written to the file17
// returns 0 if no byte is written18
// -1 if it tries to write and fails19
int writeBit ( FILE * fptr , unsigned char bit ,20
unsigned char * whichbit , unsigned char *21
curbyte ) ;22
// if * w hichbit is not 0, some bits of * curbyte are not used23
// fill these bits by 0 and write the byte to the file24
int padZero ( FILE * fptr , unsigned char * whichbit ,25
unsigned char * curbyte );26
27
int readBit ( FILE * fptr , unsigned char * bit ,28
unsigned char * whichbit ,29
unsigned char * curbyte );30
#e ndif31
// utility .c1
#in clude < stdio .h >2
Huffman Compression 441
#in clude " utility . h"3
int padZero ( FILE * fptr , unsigned char * whichbit ,4
unsigned char * curbyte )5
{6
int rtv ;7
while ((* whichbit ) != 0)8
{9
rtv = wri t eB it ( fptr , 0 , whichbit , c u r b y t e ) ;10
i f ( rtv == -1)11
{12
return -1;13
}14
}15
return rtv ;16
}17
int readBit ( FILE * fptr , unsigned char * bit ,18
unsigned char * whichbit , unsigned char * curbyte )19
20
{21
int ret = 1;22
i f ((* whichbit ) == 0)23
{24
// read a byte from the file25
ret = fread ( curbyte , s i z e o f ( unsigned char ) , 1, fptr );26
}27
i f ( ret != 1)28
{29
// read fail30
return -1;31
}32
// shift the bit to the correct location33
unsigned char temp = (* curbyte ) >> (7 - (* whichbit ) );34
temp = temp & 0 X01 ; // get only 1 bit , ignore the others35
// increas e by 136
* whichbit = ((* whic h bit ) + 1) % 8;37
* bit = temp ;38
return 1;39
}40
This is the Makefile for the program.
CFLAGS = -g - Wall - Wshadow1
GCC = gcc $ ( CFLAGS )2
SRCS = main .c encode .c freq .c tree .c list .c utility . c3
OBJS = $ ( SRCS :%. c =%. o)4
VALGRIND = valgrind -- leak - check = full -- tool = memcheck5
-- verbose --log - file6
7
code : $ ( OBJS )8
$( GCC ) $ ( OBJS ) -o code9
10
test1 : code11
442 Intermediate C Programming
./ code e input1 comp r ess112
$( VALGRIND )= logenc1 ./ code e input1 compr e ss113
./ code d compre s s1 output114
$( VALGRIND )= logdec1 ./ code d compres s 1 output115
echo # add a blank line16
diff input1 output117
18
test2 : code19
./ code e input2 comp r ess220
$( VALGRIND )= logenc2 ./ code e input2 compr e ss221
./ code d compre s s2 output222
$( VALGRIND )= logdec2 ./ code d compres s 2 output223
echo # add a blank line24
diff input2 output225
26
test3 : code27
./ code e input3 comp ress328
$( VALGRIND )= logenc3 ./ code e input3 compr e ss329
./ code d compre s s3 output330
$( VALGRIND )= logdec3 ./ code d compres s 3 output331
echo # add a blank line32
diff input3 output333
34
.c .o:35
$( GCC ) $ ( CFLAGS ) -c $ *. c36
37
clean :38
rm -f *. o a. out code log *39
This is the most complex program in this book. It integrates almost all topics in this
book. Please study this program carefully. It is a bridge for you from being an intermediate
programmer to becoming an advanced programmer.