I'm new to C so I'm having a little trouble handling everything Java already did for me in the background. Basically what I would like to achieve is this:
- Declare an array of char with no specified size
- Ask to the user a string in input (single word or phrase)
- Set the previous array of char with size of the length of the input string (dynamically)
- Put the inputed string inside the char array
I've tried using scanf but it doesn't seem to handle string as an array of char(?) so I'm not able to work on the variable I've also read about malloc() functions which dynamically allocates space for an array so I could use it to set the size of the array as the strlen of the string and then put '\0' at the end (just like .asciiz in some assembly language) but I can't figure out how to correlate malloc and input string. Any help would be appreciated! Thanks for your attention