C で書かれたプログラムがあり、ユーザーがオプション 3 を選択すると、スイッチから gets() が呼び出されます。これが私のコードです。ユーザーが何かを入力するのを待っているようには見えません。むしろ、プログラムはスイッチで続行します。
void getField();
#include <stdio.h>
#include <string.h>
/*#include "stubs.c"
#include "record.h" */
int debugMode;
void getField(){
char name[25];
char address[80];
int yearofbirth;
char telno[15];
int counter = 0;
if(debugMode == 1){
printf("***DEBUG*** Entering getField function \n");
}
printf("Enter your name:");
gets(name);
printf("Name: %s \n", name);
printf("\n");
}
void main(int argc, char * argv[])
{
struct record* start = NULL;
int userChoice;
debugMode = 0;
if(argv[1] != NULL){
if( (strcmp(argv[1], "debug") == 0) && (argv[2] == NULL) ){
debugMode = 1;
printf("Welcome, to the personal address book application \n");
}
else{
int i = 0;
while(argv[i] != NULL){
printf(argv[i]);
printf(" ");
i++;
}
printf(": Command not found \n");
userChoice = 6;
}
}
if(argv[1] == NULL){
printf("Welcome, to the personal address book application \n");
userChoice = 0;
}
while(userChoice != 6)
{
if(debugMode == 1){
printf("***DEBUG*** Entering do-while loop \n");
}
printf("Enter number corresponding number to option below \n\n");
printf("1) Add a new record in the database \n");
printf("2) Modify a record in the database \n");
printf("3) Print information about a record in the database \n");
printf("4) Print all information in the database \n");
printf("5) Delete an existing record from the database \n");
printf("6) Quit program \n\n >");
scanf("%d", &userChoice);
switch(userChoice){
case 1:
/*addRecord(start, arrayHolder, arrayHolder, 0, arrayHolder);
*/userChoice = 0;
break;
case 2:
/*modifyRecord(start, arrayHolder, arrayHolder, arrayHolder);
*/userChoice = 0;
break;
case 3:
/*printRecord(start, arrayHolder);
*/userChoice = 0;
getField();
break;
case 4:
/*printAllRecords(start);
*/userChoice = 0;
break;
case 5:
/*deleteRecord(start, arrayHolder);
*/userChoice = 0;
break;
case 6:
printf("case 6 \n");
break;
default:
printf("default \n");
userChoice = 0;
break;
}
}
printf("\n");
}