Write a program that asks for the user's last name and first name and then displays the total length of the name without counting spaces. Use the strlen function.

Example:
    Enter your first and last name : Mickey Mouse
    Hello Mickey Mouse!
    Your name is made up of 11 letters.


Difficulty level
Video recording
This exercise is mostly suitable for students
#include<stdio.h>
#include<conio.h>
#define SIZE 200

void main() {
	char name[SIZE];
	int i, j;

	printf("Enter your first and last name : ");
	//scanf("%s", name); //wrong
	gets(name);

	printf("Hello %s\n", name);
	//remove spaces from name
	for (i = 0, j = 0; name[i] != '\0'; i++)
		if (name[i] != ' ')
			name[j++] = name[i];
	name[j] = '\0';

	printf("Your name is made up of %d letters.\n"
		, strlen(name));

	getch();
}

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Program output 9