# C Programming¶

This is the C programming language section. Our intention is to present the programs of Kernighan and Ritchie here with explanation. If you like that book or like to learn C, you may find this interesting.

## Chapter 1. A Tutorial Introduction¶

- Section 1.1 Getting Started
- Exercise 1.1 - testing hello, world
- Exercise 1.2 - Experiment with printf
- Section 1.2 Variables and Arithmetic Expressions
- Exercise 1.3 - Temperature Convertor
- Exercise 1.4 - Temperature Convertor
- Section 1.3 The for statement
- Exercise 1.5 - Temperature Convertor in Reverse
- Section 1.4 Symbolic Constants
- Section 1.5 Character Input and Output
- Section 1.5.1 File Copying
- Exercise 1.6 - Verify the value of EOF
- Exercise 1.7 - Value of EOF
- Section 1.5.2 Character Counting
- Section 1.5.2 Character Counting2
- Section 1.5.3 Line Counting
- Exercise 1.8 - Count blanks, tabs and newlines
- Exercise 1.9 - Replace Continous blanks with a single blank
- Exercise 1.10 - Explicit Tabs, Backslash and Backspaces
- Section 1.5.4 Word Counting
- Exercise 1.11 - Test Word count program
- Exercise 1.12 - Print the input one word per line
- Section 1.6 Arrays
- Exercise 1.13 - Horizontal Histogram
- Exercise 1.13.2 - Vertical Histogram
- Exercise 1.14 - Histogram of Frequency of Characters
- Section 1.7 Functions
- Exercise 1.15 - Temperature Convertor using function call
- Section 1.9 Character Arrays
- Exercise 1.16 - Print length of arbitrary long input line
- Exercise 1.17 - Print lines that are longer than 80 chars
- Exercise 1.18 - Remove trailing blanks and tabs
- Exercise 1.19 - reverse a string
- Section 1.10 External Variables and Scope
- Exercise 1.20 - detab, replaces tabs with spaces
- Exercise 1.21 - entab, replaces spaces with tabs
- Exercise 1.22 - fold long lines
- Exercise 1.23 - Remove comments from a C program
- Exercise 1.24 - Check rudimentary Syntax Errors in a C Program

## Chapter 2. Types, Operators and Expressions¶

- Exercise 2.1 - Count the Ranges
- Exercise 2.2 - Write getline without && and || operator
- Exercise 2.3 - Converting Hexadecimal Digits Into Integers
- Exercise 2.4 - Compare S1, S2 To Delete Same Character in S1
- Exercise 2.5 - return the first location in the string s1 comparing s2
- Exercise 2.6 - Setting bits at a position n
- Exercise 2.7-Setting bits at a position n Inverted
- Exercise 2.8-returns the value of the integer x rotated to the right by n positions
- Exercise 2.9 - two’s complement number system
- Exercise 2.10 - upper case letters to lower case

## Chapter 3. Control Flow¶

- Exercise 3.1 - Binsearch function, writing minimum tests inside a loop
- Exercise 3.2 - escape sequences into the real characters
- Exercise 3.3 - expand short hand notation in s1 into string s2
- Exercise 3.4 - itoa to handle largest negative integer
- Exercise 3.5 - function itob, converts a integer into a string
- Exercise 3.6 - itoa with field width

## Chapter 4. Functions and Program Structure¶

- Section 4.1 - Find the pattern in the line and print it
- Exercise 4.1- strindex which returns rightmost occurance
- Section 4.2 - atof - convert string to double
- Exercise 4.2 - Extend atof to handle scientific notation
- Section 4.3 - Reverse Polish Notation Calculator
- Exercise 4.3 - RPN modulus operator and negative numbers
- Exercise 4.4 - RPN Calculator - print two top elements of the stack without popping
- Exercise 4.5 - RPN Calculator with mathematical functions
- Exercise 4.6 - RPN Calculator with variables
- Exercise 4.7 - Function ungets that will push back an entire string onto the input
- Exercise 4.8 - getch and ungetch handling pushback character
- Exercise 4.9 - getch and ungetch handling EOF Character
- Exercise 4.10 - Calculator using getline
- Exercise 4.11 - getline using static
- Exercise 4.12 - convert integer into string by calling recursive routine
- Exercise 4.13 - reverse the string s
- Exercise 4.14 - swap that interchanges two arguments of type t

## Chapter 5. Pointers and Arrays¶

- Exercise 5.1 - get next integer from input to *pn
- Exercise 5.2 - get next float from input to *pn
- Exercise 5.3 - strcat(s,t) copies the string t to the end of s
- Exercise 5.4 - strend returns 1 if string t occurs at the end of the string s
- Exercise 5.5 - simple versions of strncpy, strncat, and strncmp
- Exercise 5.6 - Find the pattern using pointers
- Section 5.6 - Pointer to Arrays
- Exercise 5.7 - Readlines using array
- Exercise 5.8 - program which has day of the year and month day
- Exercise 5.9 - program which has day of the year and month day using pointers
- Exercise 5.10 - expr, evaluate rpn from command line
- Exercise 5.11 - entab and detab which accepts arguments
- Exercise 5.12 - entab -m + which accepts arguments
- Exercise 5.13 - tail prints the last n lines of input
- Exercise 5.14 - sorting in reverse (decreasing) order
- Exercise 5.15 - fold upper and lower case together
- Exercise 5.16 - -d makes comparison on letters, numbers, blanks
- Exercise 5.17 - Sorting with options
- Exercise 5.18 - recover from input errors
- Exercise 5.19 - undcl does not add redundant parentheses
- Exercise 5.20 - dcl handling declarations with function argument types, qualifiers

## Chapter 6. Structures¶

## Chapter 7. Input and Output¶

- Exercise 7.1 - upper case to lower or lower case to upper
- Exercise 7.2 - print non-graphic characters in octal or hexadecimal
- Exercise 7.3 - minprintf to handle facilities of printf
- Exercise 7.4 - private version of scanf
- Exercise 7.5 - Postfix calculator using scanf
- Exercise 7.6 - Compare Two files
- Exercise 7.7 - Pattern matching program with files
- Exercise 7.8 - Print Pages to Files
- Exercise 7.9 - Analyze implementations of isupper

## Chapter 8. The Unix System Interface¶

- Section 8.2 - Read and Write
- Section 8.2 - Buffered and Unbuffered getchar
- Section 8.3 open and create calls
- Exercise 8.1 - program cat using read, write, open and close
- Exercise 8.2 - Rewrite fopen and _fillbuf with fields
- Exercise 8.3 - _flushbuf, fflush and fclose
- Exercise 8.4 - implement fseek
- Exercise 8.5 - inode entry
- Exercise 8.6 - Write calloc, by calling malloc
- Exercise 8.7 - Error checking by malloc
- Exercise 8.8 - bfree maintained by malloc