Answer by Bob__ for K&R Exercise 3-3: Expand Shorthand Notations (e.g. a-d to...
I'll focus on the issues of function expand which were not already exposed by the other answers.Are there any bugs with my approach?Consider writing automated unit tests to check if the function under...
View ArticleAnswer by chux - Reinstate Monica for K&R Exercise 3-3: Expand Shorthand...
Pedantic corner issues with my_getline()if (c == '\n') accesses uninitialized c when i <= 1.s[i] = '\0'; is undefined behavior when i <= 0.lim-1 is undefined behavior when lim == INT_MIN.Consider...
View ArticleAnswer by Lundin for K&R Exercise 3-3: Expand Shorthand Notations (e.g. a-d...
I strongly recommend to avoid K&R since it teaches bad style and is very much outdated. This review will focus on general C programming rather than commenting on your specific algorithm.Invalid...
View ArticleAnswer by Toby Speight for K&R Exercise 3-3: Expand Shorthand Notations (e.g....
You have run into a well-known trap in the use of the <ctype.h> functions (islower, isupper, isdigit). They take the unsigned value of a character rather than char (which may be a signed type)....
View ArticleK&R Exercise 3-3: Expand Shorthand Notations (e.g. a-d to abcd)
The following code is my answer for exercise 3-3 in K&R:#include <stdio.h>#include <ctype.h>#define MAXLINE 1000 /* maximum output line size */int my_getline(char s[], int lim);void...
View Article
More Pages to Explore .....