I have the solution but cannot understand it…
#include
main()
{
int x=0;
x=getIntegerOnly();
printf("\nYou have entered %d",x);
getch();
}
int getIntegerOnly()
{
int num=0;
int ch;
for(;;)
{ ch=getch();
if(ch>=48 && ch<=57)
{
printf("%c",ch);
num=num*10+(ch-48);
}
if(ch==13)
break;
}
return num;
}
Please explain how getch() function is working.What value gets stored in ch when we use ch=getch();.
When we declare ch as int then how does in the printf statement the value of integer gets printed even if we use %c format specifier?