Usage of fgets function in C

后端 未结 7 1627
野性不改
野性不改 2020-12-19 17:51

One of my assignments in to write my own UNIX Shell. To receive input from the user, I am using fgets to capture the input as a string but I\'m not really sure how it works.

7条回答
  •  情书的邮戳
    2020-12-19 18:24

    fgets considers the line terminator as a valid character. That's the extra character you are receiving.

    Just do something like command[strlen(command) - 1] = '\0'; to remove the line terminator. Then you are free to do all your strcmp's.

提交回复
热议问题