Usage of fgets function in C

后端 未结 7 1611
野性不改
野性不改 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:22

    Probably the easiest way to handle this is to switch to using scanf to read the input:

    char command[51];
    
    scanf("%50[^\n]", command);
    
    if (0 == strcmp(command, "exit"))
        do_something();
    

提交回复
热议问题