Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
#include <stdio.h>


int main( )
{
    char status[] = {'s','i','m','p','l','e' } ;
    char i, x ;



    printf ( "Enter character to search: " ) ;
    scanf ( "%c", &x ) ;

    for(i=0;i<=5;i++)
    {
        if ( status[5] < x || status[i] >= x )
        {
             if ( status[5] == x)
                printf ( "The character is at position %d in the array.", i ) ;
            else
                printf ( "character is not present in the array." ) ;
            break ;
        }
    }

}
Posted
Updated 7-Jun-15 0:22am
v2

1 solution

Not sure quite what some of that code is there for! Just take out the excess:
C#
int main( )
{
    char status[] = {'s','i','m','p','l','e' } ;
    char i, x ;
    printf ( "Enter character to search: " ) ;
    scanf ( "%c", &x ) ;
    for(i=0;i<6;i++)
    {
        if ( status[i] == x ) break;
    }
    if (i < 6)
        printf ( "The character is at position %d in the array.", i);
    else
        printf ( "character is not present in the array." ) ;
}
 
Share this answer
 
Comments
Usman Hunjra 9-Jun-15 14:42pm    
+5 Sir .. :)
Member 11747504 10-Jun-15 23:34pm    
thank you so much...
OriginalGriff 11-Jun-15 1:17am    
You're welcome!

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