1

Hi all,

Quite a basic question for most of you; I am trying to obtain length of a string < char name[MAX_ENTRIES][MAX_NAME_SIZE] > for use in a for loop that will perform isalpha.

for (int j=0; j < &name.length(); j++)

I am getting error 2228: left of '.length' must have class/struct/union type upon compile.

Can anyone please offer me some guidance?

This is a simple win32 console application. See attached code.

Attachments
// Get name string from user
		cout << "\n\nPlease enter name ";

		bool valid = true;

		do
		{

			cin.getline(&name[i][0], MAX_ENTRIES);

			if (&name[i][0] == '\0')
			{
				 valid = false;
			}


			for (int j=0; j < &name[i].length(); j++)
			{

				if ( !(isalpha(name[i][j])))
				{
					invalid = false;
					break;
				}
			}

			if !(valid)
			{
				cout << "\n\tInvalid name. Please try again ";
			}

		} while !(valid)
3
Contributors
2
Replies
4
Views
13 Years
Discussion Span
Last Post by ashishkumar008
0

How exactly do you want to get length?!!
The only way I know of is using <string.h> There is a strlen(char *s) function which return the strings length :D

-2

rodkay, actually I can help you in c#. In c# you can use GetLength() to get multi dimensional array. Use like this:

 for (int j = 0; j < myjaggedarraymutidim[i].GetLength(0); j++)
                {
                    for (int k = 0; k < myjaggedarraymutidim[i].GetLength(1); k++)
                    {
                        Console.Write(" "+myjaggedarraymutidim[i][j, k]+" ");
                    }

                    Console.WriteLine();
                }

Edited by mike_2000_17: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.