GithubHelp home page GithubHelp logo

fordea / c-programming-a-modern-approach Goto Github PK

View Code? Open in Web Editor NEW
309.0 24.0 151.0 976 KB

Solutions to exercises and projects in the textbook C Programming: A Modern Approach, 2nd Edition.

C 97.73% Makefile 1.35% C++ 0.92%

c-programming-a-modern-approach's People

Contributors

fordea avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

c-programming-a-modern-approach's Issues

Chapter 5, Programming Project 2 has Multiple Issues

This code has multiple issues:

`#include <stdio.h>

int main(void)
{
int hour, minute;

printf("Enter a 24-hour time: ");
scanf("%d :%d", &hour, &minute);

int ampm_hour = hour >= 12 ? hour % 12 : hour;
printf("Equivalent 12 hour time: %d:%d %s", ampm_hour, minute, ampm_hour <= 12 ? "AM" : "PM");

return 0;

}`

They include:

  1. ampm_hour is always <= 12, so the test in the second printf statement will always evaluate to "AM". The test should be "hour < 12".
  2. The input hour value "12" is converted to the ampm_hour "0", this is incorrect. The line to determine the ampm_hour should be "int ampm_hour = hour > 12 ? hour % 12 : hour".
  3. The leading zero is dropped for minute values less than ten for the output 12 hour time. The code should be "%.2d".

Chapter 5, Exercise 7 - typo

Your code is

printf("%d\n", i >= 0 ? 1 : -1);

Actually the code on the book is
printf("%d\n", i >= 0 ? i : -i);

hence I believe the answer is always 17 both when i is 17 and when i is -17

ch3, ex5, explanation....

In ex5, the explanation of the answer has some error.

When the format string "%f%d%f" in scanf processes the input "12.3 45.6 789",
the order is that:
first- for %f (x) read '1', '2', '.', '3', ' '
Since ' ' can't be the part of the item that corresponds to %f (x),
' ' is put back to the buffer and 12.3 is assigned to x;

second- for %d (i) read ' ', '4', '5', '.'
The first W.S(white space) is discarded.
Since '.' can't be the part of the item that corresponds to %d (i),
'.' is put back to the buffer and 45 is assigned to i;

third- for %f (y) read '.', '6', ' '
Since ' ' can't be the part of the item that corresponds to %f (y),
' ' is put back to the buffer and 0.6 is assigned to y;

Chapter 13, Exercise 11

since loop does not increment, this will return 0 for any two strings with the same first character.

I suggest replacing

while (s == t)
with
while (s++ == t++)

ch11 project 04 Tested failed

test ch11 project 04 by the data of "8c as 8c 7c ad 3h"

This is the data offered by the author.
The printout of the data in the book is "Pair", but your codes tests resulting "High card".
Considering the repo's last update is a few years ago, hope other friend can provide a better code.

Chapter 7, exercise 3 (03.txt)

Hi, I think I found an error in one of your files. In Chapter 7, Exercise 3, you list 4 data types and ask which ones aren't legal. Then you say:

The identifier in (c) 'short float' is not legal.

I believe the (c) should actually be (b). (b) is the 'short float'. (c) is listed as 'long double'

Ch10 exercises 02.txt

In the answer to (b) it says: "The g function: a (g parameter), b and c external variables."
But there is a local c variable declared inside the function.

chapter3 exercise2-b

hi! I think I catch some error in ex2(b).
In 03.txt, you wrote that "%d-%d-%d", "%d -%d -%d" are equivalent.
But there is a problem.
Second string can process the input, "1 -1 -1" and first string can not.
Because when scanf process the character '-', it corresponds to character ' '.
So it stops.
Sorry for my english skill TT
have a nice day!

Chapter 11 Exercise 07.c

Line 51: found = false should be found = true.

Thank you very much for putting your solution out there!

Exercise 16.8: typo spotted

Hey, I hope not to be too nitpicky, but I have found a typo in this file. There is a trailing colon which should, of course, not be there
I hope not to disturb you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.