sai_kiran_n's blog

By sai_kiran_n, history, 7 weeks ago, In English
  • Vote: I like it
  • 0
  • Vote: I do not like it

»
7 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

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 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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'