我只是迷路了。我的代码运行良好,如果我删除管理重置部分,同时,当我运行程序的管理重置部分,并输入“重置”作为参数。管理重置部分重置它需要重置的内容。简而言之,它们单独工作,但是一起运行,就像我单击build按钮(在代码块中)时一样,它将显示控制台一段时间,然后窗口将弹出一个"program.exe已停止工作“对话框。怎么了?这里我只是粘贴第一部分。
///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 {...发布于 2014-02-09 14:18:47
应该是if(argc==2 && strcmp(argv1,"reset")==0)
发布于 2014-02-09 13:14:35
我非常确信,只要稍微“调试”一下,您就能够精确地确定错误代码的位置。
看看代码块调试器如何
或者,您可以使用具有强大调试功能的Visual。
https://stackoverflow.com/questions/21659143
复制相似问题