Sunday 15 July 2012

Programming in C Evaluating characters from a string -


If the site has already been answered, apologize in advance with a character from the string in C I am trying to compare. Here is some code as an example:

  #include & lt; Stdio.h & gt; # Include & lt; Stdlib.h & gt; Four your name []; Int main () {printf ("Please enter your name: \ n"); Scanf ("% s", your_name); If (your_name [0] == "A") {printf ("Your name starts at A!"); } Else {printf ("Your name does not start with A!"); } Return 0; }   

This code does not work and I do not know why if I put it in 'Anthony', then when I indicate your_name [0] and it displays 'A' , But if the statement always fails I tried to use strcmp and which does not work (though I do not think so.)

What should I do for this assessment?

"A" is a string to compare your intended characters Instead try to compare with 'A' .

No comments:

Post a Comment