我只是输了。如果我删除admin重置部分,同时当我使用admin reset部分运行程序并输入“reset”作为参数时,我的代码运行良好。管理员重置部分重置它需要重置的内容。简而言之,它们分别在工作但它们在一起它不会运行,因为当我单击构建和运行按钮(在codeblocks中)它将显示控制台一段时间然后Windows将弹出“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 {...
答案 0 :(得分:0)
答案 1 :(得分:0)
应为if(argc == 2&amp;&amp; strcmp(argv [1],“reset”)== 0)