|
CS256 - Principles of Structured Design
Fall 2021
|
Displaying ./code/sternflCode/h6/p04.c
/*
p04.c - In this program, you are given a text file that is currently in all-caps.
You are to write a program that takes that file, changes all of the
letters to lowercase, and then just print it to the screen
You will write a function that converts the characters from uppercase to
lowercase.
You will also leave characters that mark the beginning of a sentence
alone, so in this case you will keep track of not only the current
character, but the previous two characters.
So if the previous two characters are either a period and a space, or
both newlines, you leave the character alone. Otherwise, change it to
lowercase
This file is at : /u1/h1/jcompton5/gettysburgAllCaps.txt
*/
#include <stdio.h>
int converttoLowercase(int);
int main(){
printf("%c\n", converttoLowercase('B'));
}
/*
int c; //current character
int p1 = 0; // the character right before the current character
int p2 = 0; //the character right before p1
//use fopen to open the file "/u1/h1/jcompton5/gettysburgAllCaps.txt" for reading
//loop through all the characters while the current character is not EOF
while((c = fgetc(f)) != EOF){
//you will leave the character alone if ONE of the following statements are true
// p2 is a period '.' AND p1 is a space ' '
// both p2 AND p1 are newline '\n' characters
// p1 is a 0 (indicating that we're at the start of the file)
//if none of these are true, then you will change the character to lowercase
// Hint: You can write all of the above in one if-else statement, that
// will involve a combination of logical ANDS (&&) and OR's(||) in the
// conditional statement
// or you could use a chain involving an if, two else-if's then an else,
// then you'd just need a logical AND in the conditionals
// the code will go something like this
// if above conditions are true
// use putchar function to put the character on the screen
// else
// convert the character to lowercase using the convert function
// then use putchar to put the converted character on the screen
//then make p2 equal p1, and make p1 equal c
p2 = p1;
p1 = c;
}
return 0;
}
*/
//fill out this function
int converttoLowercase(int c){
if (c>='A' && c<='Z')
return c+32;
return c;
//if c is an uppercase letter character
//change it to lowercase and return that lowercase value
// else
//just return the character, don't convert it.
// Hint: the number value of a lowercase character is always going to be 32
// bigger than their uppercase counterpart, so you could just return 32 plus
// the character, if the character is uppercase.
// Also, the if statement here will be similar to the one seen in the
// wordChar function seen in p03.c
}
|