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 and mname, respectively. The program is given below.
/* Write person’s name in abbreviated form */
char fname, mname, lname; /* 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, mname, lname);
The program output is given below.
Enter full name (first middle last): Dinesh Kumar Thakur
Abbreviated name: D. K. Thakur