| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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]; |
|
#3
|
||||
|
||||
|
I assume you would also want to put the words in quotes.
|
|
#4
|
|||
|
|||
|
Will I can't even use the library < string >
I can use <cstring> only, bcz our instructor didn't told us about it |
|
#5
|
||||
|
||||
|
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. ![]() |
|
#6
|
|||
|
|||
|
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! |
|
#7
|
|||
|
|||
|
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); |
|
#8
|
|||
|
|||
|
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 ) |
|
#9
|
||||
|
||||
|
Quote:
Quote:
|
|
#10
|
|||
|
|||
|
just to clarify, riv_rnjn: char[1][255] is the same as char[255]
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > How can I make an array of words ? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|