I'm stuck really badly on what could be causing this issue, and I really would like to understand what's happening behind the scenes for this to be occurring. The following code is meant to grab a string of max 99 character length, put it into a variable called word, and read the length; later on I am going to be reallocating the memory assigned to it by the amount of chars inside the string, but for now I just want to be able to get the input. Here's the code segment:
char* word = malloc(100);
printf("Enter a string:\n");
int x = scanf("%s", &word);
printf("Length = %d", x);
printf("Word is %s", word);
When used, this happens:
Enter a string:
123
1
Segmentation Fault
What's happening here? Why is this not working? I thought assigning memory with malloc would give it enough space, and then scanf would put my word into the variable? I need to use malloc because I need to realloc later to not use more memory than needed later.