twitter
    Find out what I'm doing, Follow Me :)

Upper And Lower Case

Load and display the program uplow.c for an example of a program that does lots of character manipulation. For a description of the stdio.h file, see the dosex_1616.c program. More specifically, uplow.c changes the case of alphabetic characters around. It illustrates the use of four functions that have to do with case. It should be no problem for you to study this program on your own and understand how it works. The four functions on display in this program are all within the user written function, "mix_up_the_line". Compile and run the program with the file of your choice. The four functions are;


isupper(); Is the character upper case?
islower(); Is the character lower case?
toupper(); Make the character upper case.
tolower(); Make the character lower case.
#include "/sys/stdio.h"
#include"/sys/ctype.h" /* Note - your compiler may not need this */
main( )
{
FILE *fp;
char line[80], filename[24];
char *c;
printf("Enter filename -> ");
scanf("%s",filename);
fp = fopen(filename,"r");
do {
c = fgets(line,80,fp); /* get a line of text */
if (c != NULL) {
mix_up_the_chars(line);
}
} while (c != NULL);
fclose(fp);
}
mix_up_the_chars(line) /* this function turns all upper case
characters into lower case, and all
lower case into upper case. It ignores
all other characters. */
char line[];
{
int index;
for (index = 0;line[index] != 0;index++) {
if (isupper(line[index])) /* 1 if upper case */
line[index] = tolower(line[index]);
else {
if (islower(line[index])) /* 1 if lower case */
line[index] = toupper(line[index]);
}
}
printf("%s",line);
}