K&R C Programs Exercise 5-20

Exercise 5-20. Expand dcl to handle declarations with function argument types, qualifiers like const, and so on. The basic dcl treats () as “function returning” but ignores argument types. This exercise adds: parameter lists inside (), type qualifiers (const, volatile), storage classes (static, extern), and the void type. The approach: when ( is encountered and …

K&R C Programs Exercise 5-19

Exercise 5-19. Modify undcl so that it does not add redundant parentheses to expressions. K&R’s undcl (Section 5.12) converts English descriptions back into C declarations. The original adds parentheses around every pointer-to-function construct, even when they are not needed. A pointer to a function needs parentheses — int (*fp)(); a simple pointer does not — …

C program To show examples of the strtol function.

C program To show examples of the strtol function.strtol() function converts the string to the long integer, and strtol() can accept the number in various bases, and converts it into the decimal number or base. Read more about C Programming Language . /************************************************************ You can use all the programs on www.c-program-example.com* for personal and learning …

K&R C Programs Exercise 5-18

Exercise 5-18. Make the basic dcl program recover from input errors. K&R’s dcl program (Section 5.12) parses C declarations into English. It calls error() which prints a message and then exits — making it useless for batch input. The fix: on error, skip to the next newline and try to continue. This requires turning dcl‘s …

K&R C Programs Exercise 5-17

Exercise 5-17. Add a field-handling capability, so sorting may be done on fields within lines, each field sorted according to an independent set of options. (The index for this book was sorted with -df for the index category and -n for the page numbers.) Fields are whitespace-delimited columns. The syntax -k<field>[flags] selects a 1-based field …

K&R C Programs Exercise 5-15

Exercise 5-15. Add the option -f to fold upper and lower case together, so that case distinctions are not made during sorting; for example, a and A compare equal. Add a fold flag. When set, the comparison function converts both characters to lowercase before comparing. The key: don’t modify the strings themselves — do the …