Dynamic allocation with scanf()

后端 未结 5 1959
孤街浪徒
孤街浪徒 2021-01-25 06:58

My question is exactly the same as this one. That is, I\'m trying to use scanf() to receive a string of indeterminate length, and I want scanf() to dyn

5条回答
  •  佛祖请我去吃肉
    2021-01-25 07:23

    Standard versions of scanf() do not allocate memory for any of the variables it reads into.

    If you've been hoodwinked into using a non-standard extension in some version of scanf(), you've just had your first lesson in how to write portable code - do not use non-standard extensions. You can nuance that to say "Do not use extensions that are not available on all the platforms of interest to you", but realize that the set of platforms may change over time.

提交回复
热议问题