C 命令行插入时,程序不会运行
我只是迷路了。我的代码运行良好,如果我删除管理员重置部分,同时当我运行程序时,管理员重置部分和输入重置作为参数。管理员重置部分重置需要重置的内容。简而言之,它们单独工作,但一起运行时不会像中那样运行。当我单击代码块中的“构建并运行”按钮时,它将在控制台上显示一段时间,然后windows将弹出一个program.exe已停止工作的对话框。怎么了?这里我只粘贴第一部分C 命令行插入时,程序不会运行,c,command-line,C,Command Line,我只是迷路了。我的代码运行良好,如果我删除管理员重置部分,同时当我运行程序时,管理员重置部分和输入重置作为参数。管理员重置部分重置需要重置的内容。简而言之,它们单独工作,但一起运行时不会像中那样运行。当我单击代码块中的“构建并运行”按钮时,它将在控制台上显示一段时间,然后windows将弹出一个program.exe已停止工作的对话框。怎么了?这里我只粘贴第一部分 ///admin reset if(strcmp(argv[1], "reset")==0){ printf("Hello
///admin reset
if(strcmp(argv[1], "reset")==0){
printf("Hello admin. You now have the power to reset the program.\n Press 'y' to proceed or press any key yo cancel: ");
fflush(stdin);
scanf("%c", &choice);
if (choice == 'y'){
remove("db.txt");
remove("phonebook.txt");
printf("Program will now exit. Thank You. Good day.\n");
}
}
///retrieve data
db = fopen("db.txt", "r");
if (db==NULL){
printf("\a");
db = NULL;
} else {
ReadLine(db, savedu, sizeof(char[16]));
ReadLine(db, savedp, sizeof(char[16]));
fscanf(db, "%d" , &cc);
pb = (Myphonebooktype*)malloc(cc*sizeof(Myphonebooktype));
addcounter = cc;
for(i = 0; i<cc ; i++) {
fscanf(db, "%d" , &pb[i].num);
ReadLine(db, pb[i].name, sizeof pb[i].name);
ReadLine(db, pb[i].address, sizeof pb[i].address);
ReadLine(db, pb[i].cellphone, sizeof pb[i].cellphone);
ReadLine(db, pb[i].email, sizeof pb[i].email);
}
}
///register and login
if(db==NULL){
while(1){
printf("Username and password should not exceed 15 charcaters\nRegister/Login (press enter to exit)\nUsername: ");
gets(username);
if (strcmp(username, "") == 0) {
option = 'X';
break;
}
if(strlen(username)>=16){
printf("\a");
printf("username should not exceed 15 characters.\n");
continue;
}
printf("Password: ");
gets(password);
if (strcmp(password, "") == 0) {
option = 'X';
break;
}
if(strlen(password)>=16){
printf("\a");
printf("password should not exceed 15 characters\n");
continue;
}
break;
}
} else {...
我非常确信,通过一点调试,您将能够确定错误代码的位置 看
或者,您可以使用具有强大调试功能的Visual Studio。应为ifargc==2&&strcmpargv[1],reset==0您收到的错误消息是什么?它只是无法运行。单击“运行”后立即退出。。。但总的来说,它不会编译——那么它会编译还是不编译呢?如果没有编译,错误消息是什么?如果它没有运行,你需要更详细地描述它,并使用调试器来找出它到底在哪里失败。顺便说一句,避免使用gets,这是非常危险的。事实上,这可能就是答案。我没有看到OP检查参数计数,因此如果他启动程序时根本没有参数argv[1],可能会导致崩溃。尽管如此,一些解释还是很好的。