I’m having issues writing a C function that reads a string from STDIN, and returns the length of said string… Suggestions?
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.
So, simply use strlen from the C standard library:
So the strlen() function is available. You just need to pass a char pointer, and it will return the string length:
Note that size_t is an integral type.
By the way, if you don’t know about this function, you should really dig into the C library, and lear about the basic functions it provides.