我希望我能提供更多信息,但我真的不知道这里发生了什么.此代码打开文件以进行附加或覆盖,具体取决于用户参数(默认情况下为appension).它可以达到用户输入的fgets,然后一旦输入输入,它就会段错误并转储核心.这很奇怪,因为在我实现参数之前(即它只是./a.out文件)它运行正常,所以我猜它与有关参数的新东西有关...
#include <stdio.h>
#include <string.h>
int printhelp(void);
int main(int argc, char *argv[])
{
char input[256];
int loopstat = 0;
FILE *inputfile;
if (argc < 2) /* Check argc for minimum 2 arguments (i.e. cw FILE) */
{
printf("ca: missing file operand\n");
return 0;
}
else if (argc > 2) /* Check argc for more than 2 arguments (i.e. cw -o FILE) */
{
if (strncmp(argv[1], "-", 1) == 0) /* if first argument begins with "-", it must be an …Run Code Online (Sandbox Code Playgroud)