To add to what Richard has said, the
printf
format code for printing a null-terminated string (like a persons name) is "%s" not "%i"
You probably want to read a name into a string of some form, so declare
aa
as an array of characters:
char aa[100];
and use the correct format code on both your
scanf
and
printf
lines.
Or better, change the name of the variable to reflect what it contains, and your code becomes more readable:
#include <stdio.h>
int main(void)
{
char characterName[100];
printf("Hello. This code will write a story, based on your choice.\n");
printf("What is the name of your character? ");
scanf("%s",characterName);
printf("Your name is %s",characterName);
return 0;
}
Note that you don't have to get the address of the variable to pass it to eit5her
scanf
or
printf
- the name of an array is defined to be a pointer to it's first element.
Also note that
scanf
will stop reading at the first whitespace character - so if your user wants to be called "Hagar the Horrible" he will end up as "Hagar" alone. To get the whole name, you probably want to call
fgets[
^] and pass it
stdin
as the stream.