In javascript I am used to just being able to pick any character from a string like “exm[2]” and it would return to me the third character in a string. In C is there a way to do that or something without a function that requires a buffer?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Since in C “strings” are just character arrays, you can do the same there, too:
More to the point, a “string” is just a pointer pointing to the first element of an array of characters ending with a zero character (‘\0’). String functions just iterate until they find that null character (which is why they have fun when it’s not there) and indexing into an array is just a fancy way of writing some pointer arithmetic:
turns into