GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 03-May-2007, 12:55
poppyjones poppyjones is offline
New Member
 
Join Date: May 2007
Posts: 3
poppyjones is on a distinguished road
Exclamation

How to endl if a string reaches a "space"


hey, this is a really dumb question, but i cant figure this out, lol
How do i endl if a user enters a string with a space in it.

example:

user enters: Jack Mc Jones
output:
Jack
Mc
Jones

here is what i have so far:

CPP / C++ / C Code:
#include <stdlib.h>
#include <iostream.h>
#define MAX_SIZE 256

void main()

{

	char name[MAX_SIZE];
	
	cout << "Enter your Full Name: ";
	cin.get(name, MAX_SIZE);


}
  #2  
Old 03-May-2007, 15:25
brink600 brink600 is offline
New Member
 
Join Date: May 2007
Location: Lebanon
Posts: 7
brink600 is on a distinguished road

Try this


Try this
Declare three strings and CIN them
in this case u can COUT them any way you want!

btw : if the strings are separated by commas each string will be CINned separately
  #3  
Old 03-May-2007, 20:00
poppyjones poppyjones is offline
New Member
 
Join Date: May 2007
Posts: 3
poppyjones is on a distinguished road

Re: How to endl if a string reaches a "space"


yes, but the problem is I dont know how much input the user is going the enter. for example:

Dell Computers Freakin Rock

output:

Dell
Computers
Freakin
Rock

see what i mean. The input could change all the time.
  #4  
Old 04-May-2007, 08:12
brink600 brink600 is offline
New Member
 
Join Date: May 2007
Location: Lebanon
Posts: 7
brink600 is on a distinguished road

Re: How to endl if a string reaches a "space"


Here is your code
CPP / C++ / C Code:
#include <stdlib.h>
#include <iostream.h>
#include <cstring>
#define MAX_SIZE 256

void main()           //special thanks to sherif

{
	//input:
	char name[MAX_SIZE];
	cout << "Enter your Full Name: ";
	cin.get(name, MAX_SIZE);
	//output:
	int M=strlen(name);
	for (int i=0;i<M;i++)
	{
		if (name[i]!=' ')
			cout <<name[i];
		else cout <<endl;
	}
}
  #5  
Old 04-May-2007, 08:43
poppyjones poppyjones is offline
New Member
 
Join Date: May 2007
Posts: 3
poppyjones is on a distinguished road

Re: How to endl if a string reaches a "space"


ah, finally, damnit i was close too. thanks for your help man.
  #6  
Old 04-May-2007, 08:46
brink600 brink600 is offline
New Member
 
Join Date: May 2007
Location: Lebanon
Posts: 7
brink600 is on a distinguished road

...:p


is there a more helpful way to thank me like feedback or something am new here but just asking ...no need
  #7  
Old 04-May-2007, 14:57
ubergeek ubergeek is offline
Regular Member
 
Join Date: Jan 2005
Posts: 775
ubergeek is a jewel in the roughubergeek is a jewel in the roughubergeek is a jewel in the rough

Re: How to endl if a string reaches a "space"


Off-topic:

CPP / C++ / C Code:
void main()           //special thanks to sherif
Whoever sherif is, he's wrong. main() always return an integer. You declare it like
CPP / C++ / C Code:
int main()
and make sure to return something (0 is customary for success, 1 for error).
  #8  
Old 04-May-2007, 15:03
brink600 brink600 is offline
New Member
 
Join Date: May 2007
Location: Lebanon
Posts: 7
brink600 is on a distinguished road

Re: Whoever sherif is


Quote:
Originally Posted by ubergeek
Off-topic:
Whoever sherif is, he's wrong. main() always return an integer.
LOL...Are you the best c++ citizen
Just keep following the rules...
I won't and still everything will work fine
  #9  
Old 06-May-2007, 20:13
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,373
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: Whoever sherif is


Quote:
Originally Posted by brink600
LOL...Are you the best c++ citizen
Just keep following the rules...
I won't and still everything will work fine
And when you get to better and more advanced compilers and you can't figure out why your programs no longer work because you've learned to write bad code, you'll wish you listened to the good citizens.

IOW, there's no excuse for bad code unless all you want to be is a bad programmer.

back

__________________

The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
 
 

Recent GIDBlogNot selected for officer school by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Message Class TransformedBG C++ Forum 5 29-Nov-2006 21:28
A Phonebook.cpp problem redthestudent C++ Forum 27 23-Jul-2005 11:10
operator overloading Krandygrl00 C++ Forum 5 06-Jul-2005 17:01
Help wit my source code compiler errors Krandygrl00 C++ Forum 1 06-Jun-2005 08:14
Reading and writing binary files in certain format Dream86 C++ Forum 10 06-Aug-2004 10:38

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 08:08.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.