c printing string syntax

Posted by user535256 on Stack Overflow See other posts from Stack Overflow or by user535256
Published on 2011-01-08T19:36:42Z Indexed on 2011/01/08 19:53 UTC
Read the original article Hit count: 332

Filed under:
|
|

Hello guys,

Just stuck on c syntax regarding strings.

Say I have a string like (name[5]="peter";) in c say if I just wanted to print the last character of string or check the last character of the string, which in this case would be 'r' how can I do this?

The way I was thinking does not seem to work

name[5]="peter";
if(name[5]=="r") printf("last character of name is r");

Question: is there some sort of function to do this that can check one character of array, is a certain value, like name[5] is 'r' in string peter or likewise name[1] is 'n'

Also how do I use printf to print that certain char, having problems using

printf("last character of name is %s",name[5]) ???

Thanks

© Stack Overflow or respective owner

Related posts about c

    Related posts about arrays