Блог пользователя sai_kiran_n

Автор sai_kiran_n, история, 7 недель назад, По-английски
  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
7 недель назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

When the length of the string is exactly $$$100$$$, fgets(s, MAX_LEN, stdin); reads only these $$$100$$$ characters and not the '\n' character after the string. Therefore, your code cannot judge the end of the string by checking whether it's '\n'.

  • »
    »
    7 недель назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    thank you! i get it now. i defined MAX_LEN as 101, but fgets reads MAX_LEN-1 which are given 100 chars but not the last entered '\n' and the condition never know when to break which causing the runtime error. the solution got accepted after i updated MAX_LEN as 102, where fgets reads till '\n'