How to input a string using scanf in c including whitespaces

后端 未结 4 781
慢半拍i
慢半拍i 2021-01-18 00:50

Example if user enters:

My name is James.

Using scanf, I have to print the full line, i.e. My name is James., then I have to get t

4条回答
  •  误落风尘
    2021-01-18 01:35

    Try:

    scanf("%80[^\r\n]", string);
    

    Replace 80 with 1 less that the size of your array. Check out the scanf man page for more information

提交回复
热议问题