logoISU  

CS256 - Principles of Structured Design

Fall 2021

Displaying ./code/sternflCode/conUpperToLower.c

/*
getting a combination of letters, digits, spaces, punctuation, etc
goal is to convert all upper case to lower case
*/

#include<stdio.h>
int main() {
   //open the file
   //get the data a character at a time
      //if its NOT upper case, just print the character
      //if its upper case, convert to to lower case, then print it

  printf("Please enter the name of the file ");
  char s[100];
  scanf("%s", s);
  FILE *f = fopen(s, "r");
  int c;
  int con = 'a'-'A';
  while ( (c=getc(f)) != EOF) {
    if (c<'A' || c>'Z') printf("%c", c);
    else {
       //c contains the code for an upper case letter
       printf("%c", c+con);
    }
  }
 






  return 0;
}