Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an array in my output that depending on my input might be empty, so in that case I want to print "empty" but I don't know how to write the if condition

What I have tried:

for (int i = 0; i<cnt;i++){
    if (locate[i]='\0'){
        cout << ""<<endl;

    }
    else
    {
        cout << locate[i] +1<<" ";
    }
Posted
Updated 11-Dec-17 18:12pm

1 solution

In my opinion, the easiest way would be to use a flag :

C++
bool empty = true;
for( int i = 0; i < cnt; ++i )
{
    if( locate[i] != '\0' )     // probably want a comparison here
    {
         empty = false;
         cout << locate[i] +1<<" ";
    }
}
if( empty )
{
    cout << "locate is empty" << nl;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900