Write a C program to enter a first name middle name and last
Write a C program to enter a first name, middle name and last name in separate variables.
After entering each name at the keyboard, call a function named convert that will capitalize the first letter of the name and set the rest of the name to lowercase (for example, jOhN becomesJohn). The convert function will be called three times-- once for the first name, once for the middle name, and once for the last name.
Combine the properly capitalized names into one string and output the string (make sure you have a space between each part of the name). Count the number of characters in the total name (including spaces between names) and output that total also.
Include descriptive comments in your source code.
Solution
#include <stdio.h>
 #include <string.h>
 #include <ctype.h>
void Convert(char string[])
 {   
 int i;
 int len = strlen(string); //compute length of string
 string[0] = toupper(string[0]); // capitalize first character of the string
 for (i=1;i<len;i++) // loop to convert all charcaters except first to lowercase
 {
 if (isalpha(string[i]) && string[i-1] != \' \')
 string[i]= tolower(string[i]);
 
 
 }
 }  
 int main(void)
 {
    char firstname[20],middlename[20],lastname[20],name[50];
   
    printf(\"\ Enter first name\");
    scanf(\"%s\",firstname);
   
    printf(\"\ Enter middle name\");
    scanf(\"%s\",middlename);
   
    printf(\"\ Enter last name\");
    scanf(\"%s\",lastname);
   
    Convert(firstname);
    Convert(middlename);
    Convert(lastname);
   
    strcat(name,firstname); //insert spaces between firstname,middlename and lastname
    strcat(name,\" \");
    strcat(name,middlename);
    strcat(name,\" \");
    strcat(name,lastname);
   
    printf(\"\ Full name : %s\",name);
   
    return 0;
 }
output:
Success time: 0 memory: 2172 signal:0


