Hey there...I discovered some bugs with my program and hope that you all will help me out with it...Its a very simple program actually but there's a little problem.....
First of all, this is the source code:
Code:
#include <stdio.h>
#include <stdlib.h>
void function1();
void function2();
int main()
{
char option[2];
do
{
printf("\n1. Function 1\n");
printf("2. Function 2\n");
printf("3. Exit\n");
printf("\nEnter an option: ");
gets(option);
printf("\n");
switch(option[0])
{
case '1':
function1();
break;
case '2':
function2();
break;
case '3':
printf("Exiting program.....\n");
exit(-1);
default:
printf("Incorrect input!! Please enter 1-3");
break;
}
}while(option[0] != '3');
}
void function1()
{
int number1;
printf("Enter a number: ");
scanf("%d",&number1);
}
void function2()
{
char string[100];
char string2[100];
printf("Enter first string: ");
gets(string);
printf("Enter second string: ");
gets(string2);
}
This is the output:
Code:
/*First time print of Menu */
1. Function 1
2. Function 2
3. Exit
/* First input to select an option*/
Enter an option: 1
/* Performing function1() */
Enter a number: 20
/* Second time print of Menu */
1. Function 1
2. Function 2
3. Exit
/* This is the bug part...It will automatically skip my option input and display the error msg... */
Enter an option:
Incorrect Input! Please enter 1-3
/*Third print of Menu*/
1. Function 1
2. Function 2
3. Exit
Enter an option: 3
Exiting Program......
Press any key to continue......
So erm...I've noted where the bug is in in the example output...Hope you all can understand and help me out with it...Thanks...