C - char pointer and char pointer string management -
I have to input a string and display it in standard out.
The ideal solution would be to get the string in the four pointer array, though I get an error on scanf, I think because the four indicator string solution is not the allocated space for it.
#include & lt; Stdio h & gt; # Include & lt; Stdlib.h & gt; #include & lt; String.h & gt; Int main (zero) {char * charString; Printf ("Input String - Max% i caratteri:", CHARARRAYSIZE); Scanf ("% s", four strings); Printf ("% s", charString); Return EXIT_SUCCESS; } So I tried to get a sting in a four array and then put a copy in the four indicator string (strakpy). In this case I got a warning that on the strcpy call, that strcpy is used without being initalized, how do I fix it?
Please refer to the code below for this second issue.
#include & lt; Stdio.h & gt; # Include & lt; Stdlib.h & gt; #include & lt; String.h & gt; # Define 16 int main (zero) {char * charString; Four charare [CHARARRAYSIZE]; Printf ("Input String - Maximum% i Characters:", CHARARRAYSIZE); Scanf ("% s", rounded); Strcpy (charString, charArray); Printf ("% s", charString); Return EXIT_SUCCESS; } Is there a way to achieve my goal and to avoid using a four array
You must allocate space for letters:
charString = malloc (CHARARRAYSIZE + 1); Later, you need to free them
free (charString);
Comments
Post a Comment