I wrote some code today to accept user input for first and last names and then make sure it's formated as such: Randy Collins
So if the user types RaNDy or rANdY or randy it will format it and then output. My program works fine, but I was wondering if there was a Standard C function I haven't found yet that will do this much easier/faster?
Code:
#include <stdio.h>
#include <string.h>
int tolower( int c );
int toupper( int c );
int main() {
char FirstName[21];
char LastName[21];
int i, x;
printf( "Please enter your FIRST name: " );
scanf( "%[^\n]%*c", FirstName );
printf( "Please enter your LAST name: " );
scanf( "%[^\n]%*c", LastName );
printf( "\nYour full name is: " )
for ( i = 0 ; FirstName[i] != 0 ; i = i + 1 ) {
for ( x = 0; x < 1; x = x + 1 ) {
printf( "%c", toupper( FirstName[i] ) );
i = 1;
}
printf( "%c", tolower( FirstName[i] ) );
}
printf(" ");
for ( i = 0 ; LastName[i] != 0 ; i = i + 1 ) {
for ( x = 0; x < 1; x = x + 1 ) {
printf( "%c", toupper( LastName[i] ) );
i = 1;
}
printf( "%c", tolower( LastName[i] ) );
}
return 0;
}