Hi All,
I am facing a strange problem in reading a character from stdin. I have wrote the following code:
Code:
#include<stdio.h>
#include<stdlib.h>
void add( int, int);
void sub( int, int);
void mul( int, int);
void swap( int, int);
void reverse( int, int);
int rev(int);
int main()
{
int num1,num2,ch;
char c='y' ;
while( c=='y' || c=='Y' )
{
printf("\n Enter The Two Numbers");
scanf("%d %d",&num1,&num2);
printf("\n Select the operation to perform from the given Menu " );
printf("\n \t 1. Addition ");
printf("\n \t 2. Subtraction ");
printf("\n \t 3. Multiplication");
printf("\n \t 4. Swap the values ");
printf("\n \t 5. Print both the numbers in reverse order");
printf("\n \t 6. Exit");
printf("\n \t Enter Your Choice ");
scanf("%d",&ch);
switch(ch)
{
case 1:
add(num1,num2);
break;
case 2:
sub(num1,num2);
break;
case 3:
mul(num1,num2);
break;
case 4:
swap(num1,num2);
break;
case 5:
reverse(num1,num2);
break;
case 6:
exit(0);
break;
}
printf(" Do You Want to continue Y/N "); //Segmentation Fault after this point
fflush(stdin);
c=getchar();
scanf("%c",&c);
}
}
I am getting the segmentation fault after printing the Line " Do You Want to continue Y/N" ..
I can't understand why it is giving the same.......
Can Anybody help me in this..........
Thanks
Bargi