scanf string in c - why can i scan more than the char[] declaration?

后端 未结 4 1426
北荒
北荒 2021-01-16 10:15

I have a program where I need to scanf a string, which I know it will be only 2 characters long. (for example: \"ex\"). what is the proper way to do that?

I was goin

4条回答
  •  误落风尘
    2021-01-16 10:49

    You can´t do that.
    scanf will do nothing to prevent it, but it can (or, in larger programs, will)
    lead to problems later on. Like unexpectly changed variable values, program crashes...

    Use fgets

提交回复
热议问题