Control in a vector

N

nick048

Hi to all,

I have this construnct:

......................
char mat [DIM], [DIM]
...................
cout << "Enter the new element" << endl;
for (i=0; i<DIM; i++)
for (j=0; j<DIM; j++)
cin >> mat[j];
...............................

How can to control, in this construct, that each element is >= 'A' and
<= 'Z'?

Thank You and Best Regards
Gaetano
 
R

Rolf Magnus

nick048 said:
Hi to all,

I have this construnct:

.....................
char mat [DIM], [DIM]

Are you sure you're talking about C++. The above makes no sense.
..................
cout << "Enter the new element" << endl;
for (i=0; i<DIM; i++)
for (j=0; j<DIM; j++)
cin >> mat[j];
..............................

How can to control, in this construct, that each element is >= 'A' and
<= 'Z'?


if (mat[j] >= 'A' | mat[j] <= 'Z')
...

But I doubt that you actually want that check. I think you want to check
whether it's an uppercase letter. In this case, you better do:

if (isupper(mat[j]) && (isalpha(mat[j]))
...
 
R

Rolf Magnus

Rolf said:
I think you want to check whether it's an uppercase letter. In this case,
you better do:

if (isupper(mat[j]) && (isalpha(mat[j]))
...


Ok, stupid me. If a character is an uppercase letter, then it's for sure a
letter, so the isalpha test can be removed:

if (isupper(mat[j]))
...
 
?

=?ISO-8859-15?Q?Juli=E1n?= Albo

nick048 said:
How can to control, in this construct, that each element is >= 'A' and
<= 'Z'?

You must consider that in C++ there is no guarantee that the alphabetic
characters, both in upper and in lower case, are in ascending order and
without gaps. ASCII and extensions of ASCII characters sets has this
property (limited to the characters currently used in english), but C++ is
not limited to that family of character sets. See EBCDIC, for example.
 
N

nick048

Hi Rolf.
Are you sure you're talking about C++. The above makes no sense.<<

This is a part of my cpp file:
int main()
{
const int DIM=100;
char mat[DIM][DIM];
char car;
int i, j;
int cont;

/*Reading of the bidimensional matrix*/
cout << "Enter your char" << endl;
for (i=0; i<DIM; i++)
for (j=0; j<DIM; j++)
cin >> mat[j];
..
..
..
}
The file work correctly.

I need to insert in the "for construct" a control that check if my char
is "uppercase letter".
If the condition is true, the "for loop" continue with the next item;
otherwise it remains.


Best Regards
Gaetano
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,610
Members
45,254
Latest member
Top Crypto TwitterChannel

Latest Threads

Top