Okay, so I figured it out and got it working. Like every other program that I have put together, I like to throw it out here so you all can chew me apart...hehe. Actually, I like to hear how I could have done something simpler or more efficient. So here it is ( and please remember, I am a novice, so please be kind ):
Code:
/* Take in a string from the user and then produce three distinct outputs:*/
/* 1) convert and print as all uppercase*/
/* 2) convert and print as all lowercase*/
/* 3) convert first letter of each word to uppercase and print*/
/* Create functions to determine if a character is upper, lower, or neither*/
/* Create a function to change the case of a character*/
/* Do this without the use of string.h*/
#include <stdio.h>
#include <ctype.h>
char firstLetUpper ( char string[] );
char upperCase ( char string[] );
char lowerCase ( char string[] );
int main ( void )
{
char string[101];
int c;
printf("Please enter a string of 100 characters or less:\n");
fgets ( string, 101, stdin ); /*gets a string from the user*/
for ( c = 0; c <= 101; c++) /* this removes the newline and replaces it with a null terminator*/
{
if ( string[c] == '\n' )
{
string[c] = '\0';
break;
}
}
upperCase ( string ); /*my function to convert all to uppercase*/
printf("%s\n", string);
lowerCase ( string ); /*my function to convert all to lowercase*/
printf("%s\n", string);
firstLetUpper ( string ); /*my function to convert the first letter of each word to uppercase*/
printf("%s\n", string);
getchar ();
return 0;
}
char upperCase ( char string[] )
{
char *p;
for ( p = string; *p != '\0'; ++p)
{
*p = toupper ( *p );
}
return 0;
}
char lowerCase ( char string[] )
{
char *p;
for ( p = string; *p != '\0'; ++p)
{
*p = tolower ( *p );
}
return 0;
}
char firstLetUpper ( char string[] )
{
char *p;
int ws = 0; /* used to check if the program is in or out of a word*/
for ( p = string; *p != '\0'; ++p){
if ( ws == 0 ){
*p = toupper ( *p );
ws = 1;
}
else{
if ( isspace ( *p )){
ws = 0;
}
}
}
return 0;
}