How to correctly input a string in C

前端 未结 5 2128
忘掉有多难
忘掉有多难 2021-01-22 14:38

I am currently learning C, and so I wanted to make a program that asks the user to input a string and to output the number of characters that were entered, the code compiles fin

5条回答
  •  野性不改
    2021-01-22 15:29

    You need to allocate space where it will put the input data. In your program, you can allocate space like:

    char i[] = "                                     ";
    

    Which will be ok. But, using malloc is better. Check out the man pages.

提交回复
热议问题