[英]command line when inserted, program wont run
我只是迷路了。 如果刪除管理員重置部分,我的代碼運行良好,與此同時,當我使用管理員重置部分運行程序並輸入“ reset”作為參數時。 管理員重置部分重置需要重置的內容。 簡而言之,它們分別處於工作狀態,但是它們一起運行的方式不會像我單擊“生成並運行”按鈕(在代碼塊中)時那樣,它將顯示控制台一段時間,然后窗口將彈出“ 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 {...
應該是if(argc == 2 && strcmp(argv [1],“ reset”)== 0)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.