P. 1
Data Structures Using C

Data Structures Using C

4.0

|Views: 1,314|Likes:
Published by TB

More info:

Published by: TB on Mar 18, 2009
Copyright:Traditional Copyright: All rights reserved

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

10/17/2011

pdf

text

original

Rewrite STRUCT1.C to dynamically allocate the two structures.

Rewrite STRUCT2.C to dynamically allocate the 12 structures.

Module 815

Data Structures Using C

Page 813-41

Objective 7After working through this module you should be able to manipulate
characters and bits.

Upper and lower case

The first example program [UPLOW.C] in this section does character
manipulation. More specifically, it changes the case of alphabetic
characters. It illustrates the use of four functions that have to do with
case. Each of these functions is part of the standard library. The
functions are prototyped in the ctype.h file, hence its inclusion in line 2
of the program.

#include "stdio.h"
#include "ctype.h"
void mix_up_the_chars(line);
void main( )
{
char line[80];
char *c;
do {

/* keep getting lines of text until an empty line is found*/
c = gets(line);

/* get a line of text

*/

if (c != NULL) {
mix_up_the_chars(line);

}
} while (c != NULL);

}
void mix_up_the_chars(line)
/* this function turns all upper case characters into lower */
/* case, and all lower case to 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);

}

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_chars. Compile and
run the program with data 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.

Many more classification and conversion routines are listed in your C
compiler’s Reference Guide.

Module 815

Data Structures Using C

Page 813-42

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->