Difference between fgets and gets

后端 未结 4 2010
面向向阳花
面向向阳花 2021-01-21 03:59

What is the difference between fgets() and gets()?

I am trying break my loop when the user hits just \"enter\". It\'s working well with

4条回答
  •  误落风尘
    2021-01-21 04:53

    The problematic difference between gets and fgets is that gets removes the trailing '\n' from an input line but fgets keeps it.

    This means an 'empty' line returned by fgets will actually be the string "\n".

    The nasty difference, that means it's best to avoid gets altogether, is that if you give gets a line that's too long your program will crash in very bad ways.

提交回复
热议问题