Jump to content

if(y[0]==let)

ichihgo
Go to solution Solved by LorenzArnua,

y[0] is the pointer to whole string

just try cout<<y[0]; and see it yourself

 

you want to access first letter of char array so y[0][0]

 

        0123

y[0]  Jack

y[1]  Sarah

y[] is an array carrying names ex.( John , Sarah )

 

let is a char ex.( J ,S, M)

 

   if(y[0]==let)
    {
        sum=sum+x;
   }
 
 
how to make the condition valid !?  
Link to comment
Share on other sites

Link to post
Share on other sites

you cant store whole string in y[0]

 

and if you want to compare strings than use strcmp();

Link to comment
Share on other sites

Link to post
Share on other sites

If you explain more you are trying to do we can help dont know which language it is

 

well let me try

 

are you tring to match first letter of chars maybe?

than in pseudo code

 

for(int i = 0; i<y.length; i++){

  if(y[0]==let){

    sum = sum+x;

  }

}

Link to comment
Share on other sites

Link to post
Share on other sites

If you explain more you are trying to do we can help dont know which language it is

 

well let me try

 

are you tring to match first letter of chars maybe?

than in pseudo code

 

for(int i = 0; i<y.length; i++){

  if(y[0]==let){

    sum = sum+x;

  }

}

are you tring to match first letter of chars maybe?

 

This and C++

Link to comment
Share on other sites

Link to post
Share on other sites

y[0]==let

it should work fine

 

This what I was missing and why y[0] can't I just use y[0] !?

 

Edit :  NVM got it :)

Link to comment
Share on other sites

Link to post
Share on other sites

y[0] is the pointer to whole string

just try cout<<y[0]; and see it yourself

 

you want to access first letter of char array so y[0][0]

 

        0123

y[0]  Jack

y[1]  Sarah

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×