problem with getting



  • When the user introduces the words and their many words into variable "b", but only 5 elements (char b[5] are available to this variable; if the user injects more than five letters, then the "was corrupted" mistake (though everyone knows) is gonna come out of the range (I can write "char b[10000];" you know, it's stupid. Heard the function helps to avoid it, and even a billion letters of entry into the char will be placed as much as you want to help me figure it out.


  • QA Engineer

    First, function gets It is no longer supported by standard C because it is unsafe. Instead, better use the function fgetsalthough the behaviour of these functions is not identical, as the function fgets It also puts the symbol of the new line in the line if it fits. The function can also be used scanf indicating the number of symbols to be read.

    Language C does not have standard containers that can change their size dynamically. So in any case, you're gonna have to use a flat size symbol and read the data.

    You can distribute this body dynamically and redesign it as necessary using the function realloc with function fgets or scanf


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2