home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / ctutor2.zip / UPLOW.C < prev    next >
Text File  |  1989-11-10  |  1KB  |  55 lines

  1.                                         /* Chapter 13 - Program 1 */
  2. #include "STDIO.H"
  3. #include "ctype.h"      /* Note - your compiler may not need this */
  4.  
  5. void mix_up_the_chars(char line[]);
  6.  
  7. void main()
  8. {
  9. FILE *fp;
  10. char line[80], filename[24];
  11. char *c;
  12.  
  13.    printf("Enter filename -> ");
  14.    scanf("%s",filename);
  15.    fp = fopen(filename,"r");
  16.  
  17.    do {
  18.       c = fgets(line,80,fp);   /* get a line of text */
  19.       if (c != NULL) {
  20.          mix_up_the_chars(line);
  21.       }
  22.    } while (c != NULL);
  23.  
  24.    fclose(fp);
  25. }
  26.  
  27. void mix_up_the_chars(char line[])
  28.              /* This function turns all upper case
  29.                             characters into lower case, and all
  30.                             lower case to upper case. It ignores
  31.                             all other characters.               */
  32. {
  33. int index;
  34.  
  35.    for (index = 0;line[index] != 0;index++) {
  36.       if (isupper(line[index]))     /* 1 if upper case */
  37.          line[index] = tolower(line[index]);
  38.       else {
  39.          if (islower(line[index]))  /* 1 if lower case */
  40.             line[index] = toupper(line[index]);
  41.       }
  42.    }
  43.    printf("%s",line);
  44. }
  45.  
  46.  
  47.  
  48. /* Result of execution
  49.  
  50. (The selected file is displayed on the monitor with all of
  51.   the upper case characters converted to lower case, and all
  52.   of the lower case characters converted to upper case.)
  53.  
  54. */
  55.