Solution for Exercise 19-20
ex1920
#include <stdio.h> int main() { char *fruit[] = { "watermelon", "banana", "pear", "apple", "coconut", "grape", "blueberry" }; int x,a; for(x=0;x<7;x++) { a=0; while(putchar(*(*(fruit+x)+a++))) ; putchar('\n'); } return(0); }
Notes
* I managed to squeeze the entire while loop operation into Line 19. It didn't have to look that way, of course, and it's really a mess. Here's how it could spread out:
All I did was move the increment of variable a
down a line. That still leaves the *(*(fruit+x)+a)
monster in the putchar() function. You could pull that down as well, though it doesn't make the code any easier to read:
* Don't fret if you didn't get this solution. This exercise wasn't an easy one. Worse: This type of solution doesn't often find itself into "real" C programs. It's just easier to use printf() to display the strings.
Copyright © 1997-2024 by QPBC.
All rights reserved