Question: every time I run this program it goes to infinit loop can you check why it can't take the input value and why it goes
every time I run this program it goes to infinit loop can you check why it can't take the input value and why it goes to infinity.
#include
#include
#include
void print_menu();
char enter_char();
int enter_oddnumber();
void print_figurePlus(char c, int n);
void print_figureX(char c, int n);
int main(void)
{
char choice=' ',C=' ';
int N=0;
//char choice;
while(choice!='Q'||choice!='q')
{
iiprint_menu(&choice);
switch(choice)
{
case 'c':
case 'C':
C=enter_char();
break;
case 'n':
case 'N':
N=enter_oddnumber();
break;
case '1':
print_figurePlus(N,C);
break;
case '2':
print_figureX(N,C);
break;
case 'q':
case 'Q':
printf("Goodbye! ");
break;
default:printf("Invalid choice! ");
}
}
//enter_oddnumber(i);
//printf(" Menu ",print_menu(c));
return 0;
}
void print_menu(char *choice)
{
printf(" Menu Choice ");
printf(" Enter/Change Character 'C' or 'c' ");
printf(" Enter/Change Number 'N'or 'n' ");
printf(" Print Plus (+) Figure or '1' ");
printf(" Print '*' Figure or '2' ");
printf(" Quite Program 'Q' or 'q' ");
scanf("%c",&choice);
}
//char choice;
//int N;
char enter_char()
{
char ch[100], c;
fgets(ch, sizeof(ch), stdin);
sscanf("%s %s", &c);
printf("%s %d ",ch);
return 0;
}
// char c;
/* char ch[10];
printf("Enter a character in fgets :");
scanf("%c",&ch);
printf("Enter in scanf:");
fgets(ch, 10, stdin);
*/
int enter_oddnumber()
{
// int i;
int i=0;
while(i>3||i>15||i%2==0)
{
int i;
printf("please enter an odd number between 3 and 15:");
scanf("%d",&i);
if(i>3||i<15||i%2==0)
{
printf("the number you entered is out of the range");
}
}
//i=enter_oddnumber();;
return i;
}
void print_figurePlus(char c, int n)
{
int i=0;
for(i=0;i { //int j; int j=0; for(j=0;j { if(i==n/2||j==n/2) { printf("%c",c); } else { printf(""); } } printf(" "); } } void print_figureX(char c, int n) { int i=0; for(i=0;i { int j=0; for(j=0;j { if(i==j||(i+j)==(n-1)) { printf("%c",c); } else { printf(""); } } printf(" "); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
