/***************************************************************************
(c) Copyright 2002 Jeremy Russell, All Rights Reserved.
http://homepage.mac.com/hteric/Project4.pdf
****************************************************************************
File : stringtest.c
Author : Jeremy Russell
Date : November 14, 2002
Description :
***************************************************************************/
#include <stdio.h>
#include <ctype.h>
#define SIZE 100
void convertAll(char *, int (*)(int));
void convertFirstToUpper(char *);
/***************************************************************************
Function :
Author : Jeremy Russell
Date : November 14, 2002
Description : Main function of stringtest.c
Arguments : void
Returns : Success or failure.
Notes :
See Also :
***************************************************************************/
int main(void)
{
char string[SIZE];
printf("Please input a line of text:\n");
gets(string);
printf("Output is:\n");
convertAll(string, toupper);
convertAll(string, tolower);
convertFirstToUpper(string);
printf("Done.\n");
return 1;
}
/***************************************************************************
Function : convertAll
Author : Jeremy Russell
Date : November 14, 2002
Description : Converts a the elements of a string dependent upon
the function passed to the routine.
Arguments : Converts the entire string to the specified character case.
Returns : void
Notes :
See Also :
***************************************************************************/
void convertAll (char *string, int (*converter)(int))
{
for (; *string != '\0'; string++){
printf("%c", (*converter)(*string));
}
printf("\n");
}
/***************************************************************************
Function :
Author : Jeremy Russell
Date : November 14, 2002
Description : The xyz() funcion ...
Arguments : Uppercases the frst character of a word and lower cases the
rest of teh word.
Returns : void
Notes :
See Also :
***************************************************************************/
void convertFirstToUpper (char *string)
{
int flag = 1;
for (; *string != '\0'; string++){
if (flag) {
printf("%c", toupper(*string));
flag = 0;
} else {
printf("%c", tolower(*string));
}
if (*string == ' ') {
flag = 1;
}
}
printf("\n");
}