Hey there, I have this problem with the gets();. My problem is that the gets(); only gets the the "Category's", and it does not allow the user to input the "Term's". Can you guys help me with this? I would be very happy if you can help me.. I think it has something to do with the function addTopic.. i'm sorry guys because it is my first time to use the gets(); because my teacher required me to..
Code:
#include <stdio.h>
struct infopairs/*Max up to 15 information pairs
usr should not be asked how many information pairs will be inputed.*/
{
char datadesc[50];/*Only one word needed*/
char dataval [150];/*Can be more than 1 word*/
};
struct theTopic/*This one consists of the following:
Term, Category and Information Pairs. This structure will
be used to add a topic.*/
{
char term[50];/*More than 1 word, 50 characters*/
char category[50];/*More than 1 word, 50 characters*/
struct infopairs descval;/*I called this desc for description
and val for value*/
};
void addTopic(struct theTopic *info)/*This one is for adding a topic.
Called the theTopic struct and named it as "info". I put the pointer
so that it will not be "passed by value".*/
{
system("cls");/*It means that the system will clear the screen*/
printf(" Adding Topic\n");/*This will be shown to users.*/
printf("\n");
printf("Please enter the term: \n");/* Tell user to enter term*/
gets(info->term);
printf("Enter the category: \n");/*Ask for the category*/
gets(info->category);
}
int main()
{ struct theTopic info;/*Declare info, info is a structure*/
int choice;/*the choice of the user from the menu*/
/*This is the menu*/
printf(" Quiz Bee\n"
"____________________________\n"
"Choose the option:\n"
"[1] Add Topic\n"
"[2] Add Information\n"
"[3] Delete Topic\n"
"[4] Delete Information\n"
"[5] View All Topics\n"
"[6] View By Category\n"
"[7] View Specific Term\n"
"[8] Export\n"
"[9] Import\n"
"[0] Exit\n");
scanf("%d", &choice);/*Get user's choice*/
/*User's choice will have outcomes by using switch*/
switch(choice)
{
case 1: system("color 2b");
addTopic(&info);/*addTopic will be used if '1' is pressed.
Address of info will be passed on to the addTopic.*/
break;
case 2: break;
case 3: break;
case 4: break;
case 5: break;
case 6: break;
case 7: break;
case 8: break;
case 9: break;
case 0: break;
}
system("pause");/*pauses system*/
return 0;/*Returns a 0*/
}
}