Skip to content

This is my notes, mostly gonna be Exercise solutions from the famous K&R (Kernighan & Ritchie) "The C Programming Language" book.

Notifications You must be signed in to change notification settings

ahmetgello/my_the_c_programming_language_solutions

Repository files navigation

my_the_c_programming_language_solutions

This is my notes, mostly gonna be Exercise solutions from the famous K&R (Kernighan & Ritchie) "The C Programming Language" book.

When I delete the include stdlib.h library. I get compilation error because 'printf' function is not declared anymore.
When I delete main(). I get expected identifier or '('. I think identifier is main.
When I delete first curly bracket '{': I get expected function body after decleration, pretty intuitive. And I get: Extraneous closing brace '}'.
When I delete printf: the program runs, but don't print anything.
When I delete the last brace '}' I get: expected '}' to match the first one.

Get a warning that \c is an unkown escape sequence.
Prints 'c' but not the backslash ''.

Added header. Changed some %3f to #5f for more space.

Celsius to Fahrenheit

Learned to define constants.
Printing the table in reverse oreder with a reverse style for loop.

We make a variable and assign getchar() != EOF to it, then print the variable.
Prints 1 when EOF is typed.

Just putchar or printf with %d.

Counts blanks, tabs, and new lines with a while loop until it's EOF.
Check every character in the loop.

Has two ints c and prev_char, if current character is equal to the prev character and it's equal to a blank don't do anyting 'continue', else print the character.

Need to use printf not putchar, it's a bit tricky because backslash is weird.

Exercise 1-11

Test by giving different texts.
Things like 2 blanks ' ', or a new line may uncover errors.

Printing a new line every encounter of a unique blank.
It would be better if it wasn't printing a line when a blank is preceeding or at the end.

Checking for word end and start by usnig the previous method of: state = IN/OUT.
We print the histogram when it's out of a word.

Storing frequency of characters in an array.
We add 1 to the c - 'a' character for each character.

The same 1.2 Section program, but using a funcion.

Revised the program, and changed MAXLINE constant to INT16_MAX.

Printing lines that are longer than MINIMUM constant.
I made it so that you input line by line, because I see that using EOF is weird.

I count preceeding blanks with a while loop.
Then copy line to cleanline with removed blanks.

Added reverse() funciton, it make temp array. assigns value in reverse.

Found out different variables.
Prints char, int, and long maximum.

The same 1-16 exercise i think.
Instead of && we can add and check if equal to 3, since a true expression is a 1.

htoi() takes pointer array s and array length.
starts from the last element in the string.
Calculates power of place by taking powers of 16.
Adds the value of the hex number to ans.
This was a good question, I liked it.

About

This is my notes, mostly gonna be Exercise solutions from the famous K&R (Kernighan & Ritchie) "The C Programming Language" book.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages