I'm very new to C. I'm trying to figure out how to print out an user input that is made of chars including spaces. For example "-- John Smith --" should print out "-- John Smith --".
The following code works when the string has no spaces, but otherwise nothing happens. I did read that the scanf
function does not read spaces, and we should use the fgets
functions instead, but I can't seem to get it to work.
#include <stdio.h>
char *str[];
void main() {
print_string();
}
void print_string() {
scanf("%s", &str);
printf("%s", str);
}