C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 29th, 2005, 12:11 PM
hessa hessa is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 11 hessa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 54 m 7 sec
Reputation Power: 0
Question How can I make an array of words ?

How can I make an array of words ?
(the user input the words)
For example,
array[0] = car
array[1] = bus
array[2] = house
array[3] = store

Reply With Quote
  #2  
Old April 29th, 2005, 12:51 PM
Rediahs Rediahs is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 13 Rediahs User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 19 m 19 sec
Reputation Power: 0
In C++, use strings. Sorry, I don't know C if that's what you mean. It might be the same though.

#include <string>

string array[5];

Reply With Quote
  #3  
Old April 29th, 2005, 02:39 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
I assume you would also want to put the words in quotes.

Reply With Quote
  #4  
Old April 29th, 2005, 08:02 PM
hessa hessa is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 11 hessa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 54 m 7 sec
Reputation Power: 0
Post none

Will I can't even use the library < string >
I can use <cstring> only, bcz our instructor didn't told us about it

Reply With Quote
  #5  
Old April 29th, 2005, 08:32 PM
B-Con's Avatar
B-Con B-Con is offline
:bcon: moderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Location: int main()
Posts: 351 B-Con User rank is Private First Class (20 - 50 Reputation Level)B-Con User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 23 h 8 m 6 sec
Reputation Power: 4
use a multi-demensional array, each array will then be it's own array that will hold the word, ie:
Code:
char words[3][10];
strcpy(words[0],"one");
strcpy(words[1],"two");
__________________
Officially a member of the Itsacon fan club. Beer blasts are every friday at Viper_SB's house. I bring the chips.



Reply With Quote
  #6  
Old May 1st, 2005, 01:50 PM
hessa hessa is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 11 hessa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 54 m 7 sec
Reputation Power: 0
Question

Hey!

Im supposed to do this:

input the information of 10 employees:
Steve
John
Michael
Susan
Taylor
.
.
.


So basically, the user should enter 10 names, and im suposed to put each of these names in
one element of an array each.

So when i refer to a[0], I'd be refering to Steve.

for ( int i=0; i < 10; i++)
cin >> a[i];

This doesn't work!!

HELP!

Reply With Quote
  #7  
Old May 1st, 2005, 03:26 PM
ubergeek ubergeek is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2005
Posts: 600 ubergeek User rank is Private First Class (20 - 50 Reputation Level)ubergeek User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 40 m 27 sec
Reputation Power: 4
Send a message via AIM to ubergeek
Code:
#include <iostream>
using namespace std;

int main()
{
char names[10][100];

for (int i = 0; i < 10; i++)
{
cout << "Please enter a name (not more than 99 letters long and no spaces): ";
cin >> names[i];
}

return 0;
}

That should work. If you want to be able to have spaces in the names then instead of
Code:
cin >> names[i];

use
Code:
cin.getline(names[i], 99);

Reply With Quote
  #8  
Old May 2nd, 2005, 04:21 PM
hessa hessa is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 11 hessa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 54 m 7 sec
Reputation Power: 0
This doesn't solve my problem
, bcz after the user unput 10 names
I shoud ask him about the name he's searching for
then I'll output the information about this name,

then I shoud use ( strcmp )

Reply With Quote
  #9  
Old May 3rd, 2005, 06:43 AM
rjv_rnjn rjv_rnjn is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2005
Posts: 3 rjv_rnjn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 18 m 40 sec
Reputation Power: 0
Quote:
Originally Posted by hessa
This doesn't solve my problem
But there doesn't seem you have a complete problem. Your initial problem statement says that you wanted to read 10 names, now that's done.
Quote:
Originally Posted by hessa
bcz after the user unput 10 names
I shoud ask him about the name he's searching for
then I'll output the information about this name
After getting all the names, all you have to do is read an input from the user in another 2-D variable (this time only char[1][255]) and then use the strcmp (or much better _stricmp() to avoid the case sensitiveness).

Reply With Quote
  #10  
Old May 3rd, 2005, 09:14 PM
ubergeek ubergeek is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2005
Posts: 600 ubergeek User rank is Private First Class (20 - 50 Reputation Level)ubergeek User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 40 m 27 sec
Reputation Power: 4
Send a message via AIM to ubergeek
just to clarify, riv_rnjn: char[1][255] is the same as char[255]

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > How can I make an array of words ?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT