How do you allow spaces to be entered using scanf?

前端 未结 11 1996
我寻月下人不归
我寻月下人不归 2020-11-21 06:05

Using the following code:

char *name = malloc(sizeof(char) + 256); 

printf(\"What is your name? \");
scanf(\"%s\", name);

printf(\"Hello %s. Nice to meet y         


        
11条回答
  •  悲哀的现实
    2020-11-21 06:29

    getline()

    Now part of POSIX, none-the-less.

    It also takes care of the buffer allocation problem that you asked about earlier, though you have to take care of freeing the memory.

提交回复
热议问题