POPMUISE
\n当用户按Enter键时,fgets会向用户提供的字符串附加一个。你可以通过使用strcspn或只是添加\n到你想要比较的字符串的末尾来解决这个问题。printf("Please enter put FILE_NAME (foo1, 2, or 3), ls, or exit: \n");fgets(temp, 8, stdin);temp[strcspn(temp, "\n")] = '\0';if(strcmp(temp, "ls") == 0 || strcmp(temp, "exit") == 0)这只是取代了\na \0,但如果你想要懒惰,你可以这样做:printf("Please enter put FILE_NAME (foo1, 2, or 3), ls, or exit: \n");fgets(temp, 8, stdin);if(strcmp(temp, "ls\n") == 0 || strcmp(temp, "exit\n") == 0)但它并不那么优雅。