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 — …

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 …

C Program to demonstrate strpbrk function.

Write C programt to demonstrate strpbrk function.strpbrk function locate the first occurrence pointed by the of string s1 from the string pointed to by s2. In this program, We Turns miscellaneous field separators into just a space separating tokens for easy parsing by SSCANF. Eventually, the character separators and replacement character will be passed in …

K&R C Programs Exercise 5-12

Exercise 5-12. Extend entab and detab to accept the shorthand entab -m +n to mean tab stops every n columns, starting at column m. Choose convenient (for the user) default behavior. Two new argument forms extend the programs from Exercise 5-11: -m sets the starting column and +n sets the interval. So detab -4 +3 …