K&R C Programs Exercise 4-14

Exercise 4-14. Define a macro swap(t,x,y) that interchanges two arguments of type t. (Block structure will help.) A three-argument swap macro: t is the type, x and y are the variables to swap. The block { … } creates a local scope for the temporary, preventing name leakage. The conventional temp variable name _swap_tmp (with …

K&R C Programs Exercise 4-12

Exercise 4-12. Adapt the ideas of printd to write a recursive version of itoa; that is, convert an integer into a string by calling a recursive routine. K&R’s printd (Section 4.10) prints a number recursively: recurse on n/10 to print all leading digits first, then putchar(n%10 + ‘0’) on the way back up. itoa must …

C Program to find sum and product using macros.

Write C Program to find sum and product using macros.Macro is a piece of text that is expanded by the preprocessor part of the compiler. This is used in to expand text before compiling. Macro definitions (#define), and conditional inclusion (#if). In many C implementations, it is a separate program invoked by the compiler as …

K&R C Programs Exercise 4-9

Exercise 4-9. Our getch and ungetch do not handle a pushed-back EOF correctly. Decide what their properties should be if an EOF is pushed back, then implement your decision. The bug: K&R’s original implementation uses char buf[BUFSIZE]. When ungetch(EOF) is called, EOF (typically -1) is stored as char. On platforms where char is unsigned, -1 …

C Program which produces its own source code as its output.

Write a c program which produces its own source code as its output.This C program uses the C File i/o operations like fopen(), fclose(). In this program, We pritn the source code of the program.Read more about C Programming Language . /************************************************************ You can use all the programs on www.c-program-example.com* for personal and learning purposes. …

K&R C Programs Exercise 4-8

Exercise 4-8. Suppose that there will never be more than one character of pushback. Modify getch and ungetch accordingly. The original K&R implementation uses an array buf[BUFSIZE] and an index bufp to support multiple pushed-back characters. If only one character of pushback is ever needed, the array becomes unnecessary. A single static int buf suffices …