How do I count the number of indexes used in an array

This is a C++ question
Write a program that asks the user to enter their name. First Name and Last Name are entered separately by the user. The program then tells the following:
• Which part (First name, or Last name), has more character, and how many more characters.
• Total number of vowels used in the complete name.
• Tells the user if the First Name and Second Name are same.
This is my assignment and we cannot use strings library. We are supposed to use the character arrays to go about doing this.

Up till now I haven’t been able to understand how can I figure out the number of indexes I use to store characters.

int main()
	int count = 0;
	cout << "Enter you first name: ";

	char arr[10];

	cin.getline(arr, 10);

	for (int i = 0; i < 10; i++) {
		if (arr[i] != ' ') {
		else {

	int x= sizeof(arr) / sizeof(arr[10]);
	cout << arr;
	cout << endl << count<< endl<<x;
return 0;

but still I haven’t come around to a solution.

I can help with this, but one question, why limit the first name to 10?

It doesn’t look like you’re reading in the last name yet either.

What is the variable ‘x’ supposed to represent in your code?

It is a good habit to have descriptive variable names.

I first made an array of 100 size but changed it to 10 for no reason.

Haven’t gotten around to it yet.

x was used to show the total size of array.

yeah sorry I forgot that .

It looks like your comparison is slightly off.

It contains the null terminator , which is represented by the \0

1 Like

I didn’t think of it.

1 Like