Thread: Is there a standard C function to do this?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    28

    Is there a standard C function to do this?

    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;
    }
    Last edited by lucidrave; 08-14-2009 at 09:14 AM. Reason: misc

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Change this program so it uses function??
    By stormfront in forum C Programming
    Replies: 8
    Last Post: 11-01-2005, 08:55 AM
  3. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM
  4. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM
  5. Replies: 5
    Last Post: 02-08-2003, 07:42 PM