I want to handle some char variables and would like to get a list of some functions that can do these tasks when it comes to handling chars.
- Getting first characters of a char (var_name[1] doesnt seem to work)
- Getting last characters of a char
- Checking for char1 matches with char2 ( eg if “unicorn” matches words with “bicycle”
I am pretty sure some of these methods exist in libraries such as stdio.h or so but google isnt my friend.
EDIT:My 3rd question means not direct match with strcmp but single character match(eg if “hey” and “hello”) have e as common letter.
var_name[0]to get first character (array indexes run from0toN - 1, whereNis the number of elements in the array).var_name[strlen(var_name) - 1]to get the last character.strcmp()to compare twocharstrings.EDIT:
To search for character in a string you can use
strchr():There is also
strpbrk()function that would indicate if two strings have any common characters:Assuming you mean a
char[], and not acharwhich is a single character.