Display first name only

If I were to enter a name with first name, middle initial, and last name, how would I get it to display just the first name using members of <cstring>?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <cstring>
using namespace std;

int main()
{
	char name[50];

cout << "Enter your full name: ";
cin.getline (name, 50);
cout << "Your name's length is: " << strlen (name) << endl;
strlwr(name);
cout << "Your name in lower case: "<< name << endl;
strupr(name);
cout << "Your name in upper case: " << name << endl;


//Help?
cout << "Your first name is: " << endl;

system ("pause");
return 0;
}
Why are you mixing C and C++?
@Lindseybb

Here's a way.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Display First Name.cpp : main project file.

#include <iostream>
#include <cstring>

using namespace std;

int main()
{
	char name[50];

cout << "Enter your full name: ";
cin.getline (name, 50);
cout << "Your name's length is: " << strlen (name) << endl;
cout << "Your first name is : "; // Moved it here so name printed would not be all caps
for(int i=0;i<strlen (name);i++)
	if(name[i]!=' ')
		cout << name[i];
	else
	   break;
cout << endl;
strlwr(name);
cout << "Your name in lower case: "<< name << endl;
strupr(name);
cout << "Your name in upper case: " << name << endl;

system ("pause");
return 0;
}
Yay it works! Thank you for your help!
Topic archived. No new replies allowed.