![]() |
|
#1
|
|||
|
|||
Storing strings in an array...got another one for you guys...
i need to take up to 15 names from the user, and store them in an array. here's what i have so far... CPP / C++ / C Code:
thanks in advance. ryan |
|||
|
#2
|
|||
|
|||
Re: Storing strings in an array...It looks like the code you have to save the name is
CPP / C++ / C Code:
CPP / C++ / C Code:
|
|
#3
|
|||
|
|||
Re: Storing strings in an array...thanks, ill give that a shot. kudos to a quick response, too.
|
|
#4
|
|||
|
|||
Re: Storing strings in an array...hmm, i switched them around, same result. i played around with my cout statement some...
if i use CPP / C++ / C Code:
if i use CPP / C++ / C Code:
what do i want to use in that cout statement? if i use CPP / C++ / C Code:
|
|
#5
|
|||
|
|||
Re: Storing strings in an array...It's hard to guess what you've done without seeing all of the new code. The key is to make sure you store the newly inputted string in an array before overwriting the variable.
|
|
#6
|
|||
|
|||
Re: Storing strings in an array...CPP / C++ / C Code:
i'm a little closer with this one. i forgot that i need a loop to print out all the names stored. added the loop, and the program now prints out the correct number of names, but it prints out either "finished" or the last name entered for each entry. ex: if the user inputs "red, green, blue," then "finished," i get "finished, finished, finished," for my output. any ideas? |
|
#7
|
|||
|
|||
Re: Storing strings in an array...What you posted will not compile for me. I get the following errors.
error C2057: expected constant expression (int max = 14;) error C2466: cannot allocate an array of constant size 0 (string totnames[max];) error C2133: 'totnames' : unknown size (string totnames[max];) error C2059: syntax error : '<<' (cout << << endl;) But with fixing those errors I get this output. Enter a name. Enter 'finished' to stop. red, green, blue," then finished Enter another name. Enter 'finished' to stop. Enter another name. Enter 'finished' to stop. Enter another name. Enter 'finished' to stop. Enter another name. Enter 'finished' to stop. You have entered the following names: red, green, blue," then |
|
#8
|
|||
|
|||
Re: Storing strings in an array...fixed it, sorry. i forgot to put the "name" back in the cout statement, hence the two <<'s. i appreciate the help, but i dont know what those errors mean. care to explain?
|
|
#9
|
|||
|
|||
Re: Storing strings in an array...Quote:
http://msdn.microsoft.com/library/de...html/C2057.asp Where did you store the names(in what variable)? |
|
#10
|
|||
|
|||
Re: Storing strings in an array...im attempting to store the names entered into the variable "name," and then put the different "name"s into an array, that i can search (that comes later).
|
Recent GIDBlog
Toyota - 2009 May Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to clear the strings in the array? | jpxtreme | C Programming Language | 9 | 29-Sep-2006 07:41 |
| Need help deleting the last element in the array | headphone69 | C++ Forum | 2 | 15-Mar-2006 20:31 |
| Declaring an array of strings dynamically (C Language) | Hyuga | C Programming Language | 5 | 03-Aug-2005 10:18 |
| template comiling problems - need expert debugger! | crq | C++ Forum | 1 | 01-Feb-2005 22:26 |
| array of pointers to strings | mirizar | C++ Forum | 5 | 21-Jan-2005 11:24 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The