Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / May 2004

Tip: Looking for answers? Try searching our database.

Array Name

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John - 02 May 2004 07:51 GMT
                    Hello, I need some help with something simple.  How would I be able to display two or three names in an array?  So, if I have an array calle

Names[ 3 ] = { 10, 10, 10 };  //Names can hold up to three names with 10 characters each. First I want to let the User to type his/her name up to three times.  How do I let the make the element in the array count in the while loop??? For example:  ....  Please help me!!!!!

  while ( count < 3 ) // until three names are entere

   console :: write( " Please enter your name: ")
  // person types in nam
}
saleem ullah khan - 03 May 2004 22:57 GMT
try some thing like this
  while ( count < 3 ) // until three names are entered
{
   console :: write( " Please enter your name: ");
  Name[count].put(); ///like Name[count].gets()
   // person types in name
}

or either

CString temp;
char ch;
while(count<3)
{
console::print("Enter ur Name");
while(inner<10)
{
ch = getche();
if( "check for required input")
{
strcat(temp, toStr(ch);
inner++;
}
}
ch =  '\0'; \null  character
temp = "";
inner = 0;
}
Vas - 04 May 2004 05:21 GMT
Have a look at the Array class, all managed arrays inherit from this. It has copy functions and the like

Looking at your example, you've made a wrong assumption, or I have if "Name" means something else

Name[3] = {10,10,10}

This doesn't create 3 strings of 10 characters, it creates an array of 3 elements and each element is initialised with the value 10. When dealing with character strings you'll need to use an array of pointers

char* ptr[3] = {"Name1", "Name2", "Name3"}

This creates an array of 3 pointers to character strings, each one initialised to "Name#" respectively. The length of each element is set to the length of the initialiser

You don't have to initialise straight off though, you can do that when needed

char* ptr[3]

ptr[0] = new char[11];  // 10 for the characters and 1 for the '\0' terminator = 11

This is all low level stuff, from "C". .Net has classes for string manipulation, look at "String" and "StringCollection" classes for more examples

If you want some "C" style examples, checkout the "C" section at www.freshsources.com

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.