C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming
The ASP Free website provides in-depth information on the latest developer tools available from Microsoft. Our cadre of writers, highly experienced industry experts, reveals the best ways to use established technologies as well as new and emerging technologies. Our coverage of Microsoft's development and administration technologies is among the most respected in the IT industry today.

ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month!
Download and Activate to enter!

Intel® Graphics Performance Analyzers is a powerful tool suite for analyzing and optimizing your games, media, and graphics-intensive applications. Used by some of the best developers on the planet, Intel GPA lets you maximize your app’s performance.


Tutorials
| Forums

Download to Enter
| Contest Rules

DOWNLOAD INTEL® GPA FOR FREE

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 8th, 2004, 07:04 PM
DirkPitt's Avatar
DirkPitt DirkPitt is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: New Zealand
Posts: 295 DirkPitt User rank is Sergeant (500 - 2000 Reputation Level)DirkPitt User rank is Sergeant (500 - 2000 Reputation Level)DirkPitt User rank is Sergeant (500 - 2000 Reputation Level)DirkPitt User rank is Sergeant (500 - 2000 Reputation Level)DirkPitt User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 5 h 8 m 38 sec
Reputation Power: 16
char array index position

Hi all.

Im trying to take inputs of a user and enter them into a char array in a loop.


for(count=1; count<=amount;count++)
{ cout<<"\n enter string.. \n";
cin.getline(user_input,100);
}

then I want to increment the array by 1 so that the user can input another string which can be stored in the next position of the array.

my problem is doing this with the cin.getline function.

can i do this without a 2d array, (i have been told i can)
and could someone help me with the code.

I also have no idea how to output that array again.
hope thats clear.

cheers Dirk

Reply With Quote
  #2  
Old January 8th, 2004, 09:05 PM
theRaginCajun theRaginCajun is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: USA
Posts: 144 theRaginCajun User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
it looks like you're using c++ and you're wondering if you can do it without a 2d array so why not use strings (or a 1d array of strings)?


Code:

string name_array[3];

for (int i = 0; i < 3; i++)
{
    cout << "enter a name: ";
    cin  >> name_array[i];
}

cout << endl << endl << endl;

for (int i = 0; i < 3; i++)
    cout << name_array[i] << endl;


just include <string> and you can use them they are fantastic. By the way, I would also use a vector of strings instead of an array so that you don't have to worry about overflowing the array.

Reply With Quote
  #3  
Old January 8th, 2004, 09:39 PM
DirkPitt's Avatar
DirkPitt DirkPitt is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: New Zealand
Posts: 295 DirkPitt User rank is Sergeant (500 - 2000 Reputation Level)DirkPitt User rank is Sergeant (500 - 2000 Reputation Level)DirkPitt User rank is Sergeant (500 - 2000 Reputation Level)DirkPitt User rank is Sergeant (500 - 2000 Reputation Level)DirkPitt User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 5 h 8 m 38 sec
Reputation Power: 16
Thankyou

Thanks for that I ended up solving it using a 2d array but your way looks a hell of allot simpler (cheers)

Dirk

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > char array index position


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

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


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.

© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap