使用下面的代码:
```python print("Hello, World!") ```
char *name = malloc(sizeof(char) + 256);
printf("What is your name? ");
scanf("%s", name);
printf("Hello %s. Nice to meet you.\n", name);
用户可以输入他们的名字,但当他们输入一个带空格的名字,比如Lucas Aardvark
,scanf()
只会截取Lucas
后面的所有内容。我该如何让scanf()
允许空格?
sizeof(char) + 256
是一个笔误。 - Chris Lutz