How could I make this please:
Code:#include <stdio.h> int main( void ) { char *name; scanf( "%s", &name ); // error? printf( "Hi %s", name ); }
How could I make this please:
Code:#include <stdio.h> int main( void ) { char *name; scanf( "%s", &name ); // error? printf( "Hi %s", name ); }
Last edited by qertyer; 06-20-2017 at 10:52 AM.
You have not allocated any data space for name.
Try this:
Code:#include <stdio.h> int main( void ) { char name[256]; scanf( "%s", &name ); // error? printf( "Hi %s", name ); return 0; }
Actually, the scanf() above should be:
The above code will only input one word, not a full line. Alternatively, you could try:Code:scanf( "%s", name );
Allow for one space for the Nul byte at the end of the array, if 255 or more chars entered.Code:scanf( "%255s", name );