khalfella

ansi_c_pg41_ch02_ex02.c

Nov 2nd, 2014
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. /*
  2. * Exercise 2-2.
  3. * Write a loop equivalent to the for loop above without using && or ||.
  4. */
  5.  
  6.  
  7. #include <stdio.h>
  8. #include <limits.h>
  9. #include <float.h>
  10.  
  11. #define MAX 100
  12.  
  13. int
  14. main() {
  15. int c, i = 0;
  16. int lim = MAX;
  17. char s[MAX];
  18.  
  19. while (i < lim - 1) {
  20. if ((c = getchar()) != '\n') {
  21. if (c != EOF) {
  22. s[i++] = c;
  23. continue;
  24. }
  25. }
  26.  
  27. break; /* if any of the above conditions failed, break the loop */
  28. }
  29.  
  30. return (0);
  31. }
Advertisement
Add Comment
Please, Sign In to add comment