I’m new to C. I need to know how to ask for the user input, which could be an arbitrary number of words, and then put the characters into an array.
I know this shouldn’t be too hard to answer, but Google is just confusing me.
Thanks in advance
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.
If I understand your problem correctly, what you need is to read user input of some unknown size, thus store this information into a char array, right? If this is the case, one possible solution would be to have an char array with which should be allocated to a default fixed size, this dynamically reallocate it’s size on the fly.
Once looping over the characters of the input, while verifying that you haven’t hit an EOF, you should append the char to the array. The trick is then to check whether the array is large enough to hold the characters from the user’s input. If not, you have to reallocate the array’s size.
A sample implementation of a solution could look somewhat like this:
Performance wise, I am not all to sure this may be the best solution, but I hope this may aid you on solving your problem.
Kind regards
~ E.