Ajit N

Ajit N

  • 1.3k
  • 352
  • 68.2k

how to solve error "stack around variable was corrupted" ?

Sep 29 2019 12:23 PM
Hi, i got error in c program. the program is on arithmatic operation, in this output displaying properly, but when i press enter after seeing output then it will show me error like "stack around variable ch was corrupted"
 
below is my sample code
  1. #include<stdio.h>  
  2. #include<conio.h>  
  3.   
  4. void Add(int x,int y)  
  5. {  
  6.     printf("%d",x+y);  
  7. }  
  8.   
  9. void main()  
  10. {  
  11.     int a;  
  12.     int b;  
  13.     char ch;  
  14.     scanf("%d",&a);  
  15.   
  16.     scanf("%s",&ch);  
  17.   
  18.     scanf("%d",&b);  
  19.   
  20.   
  21.     switch (ch)  
  22.     {  
  23.     case '+':  
  24.         Add(a,b);  
  25.         break;  
  26.       
  27.     }  
  28.   
  29.     getch();  
  30. }  
so help me how can i solve this ? 

Answers (1)