by Dinesh Thakur

Let us use character arrays fname, mname and lname to store the first name, middle name and last name of a person. The program given below first accepts the full name, i. e., values of fname, mname and lname using a scanf function. Then the name is printed in the desired abbreviated form using a printf function. The initial letters of fname and mname are printed using fname [0]and mname[0], respectively. The program is given below.

/* Write person's name in abbreviated form */

#include <stdio.h>

int main()


    char fname[20], mname[20], lname[20]; /* person's name */

      /* accept full name */

     printf("Enter full name (first middle last): ");

     scanf("%s %s %s", fname, mname, lname);

      /* print abbreviated name */

     printf("Abbreviated name: ");

     printf("%c. %c. %s\n", fname[0], mname[0], lname);

     return 0;


The program output is given below.

Enter full name (first middle last): Dinesh Kumar Thakur

Abbreviated name: D. K. Thakur