c printing string syntax
- by user535256
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