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