lolamontes69

K+R Exercise2_10

Sep 5th, 2014
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.54 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3.  
  4. int lower(int c);   // If const is passed it must be declared
  5.  
  6. int main()
  7. {
  8.     int i, c;
  9.  
  10.     printf("Enter characters >");
  11.     while((c=getchar())!=EOF && c!='\n') {
  12.         i = lower(c);
  13.         printf("%c",i);
  14.     }                      
  15.     puts(" ");
  16.     return(0);
  17. }
  18.  
  19. /* lower: convert c to lower case; ASCII only */
  20. int lower(int c)
  21. {                                                    //  a ? b : c
  22.     c = (c>='A' && c<='Z') ? (c+'a'-'A') : c;        // if a return b else return c
  23.     return c;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment