this can be solved like this
Code:
#include<stdio.h>
#include<conio.h>
int main(){
int i=0;
printf("enter key a to stop running");
char a='o';
while(a!='a'){
while(!kbhit()){
printf("\n%d",++i);
}
a=getch();
}
printf("\nyou pressed a and stopped the process!!!");
getchar();
}