Erase Function

below code will print Hey until i don't press 'a' i want a code which can also erase the statement on screen
with explanation if possible

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  #include<stdio.h>
#include<conio.h>

 void rep();
 int main()
 {
     clrscr();

     printf("Hey! Please press 'a' to exit...\n");
     rep();
     getch();
 }

 void rep()
 {
     printf("Hey\n");  
     if(getch() != 'a') rep(); 
     printf("bye"); return;
 }
Hi,
> Below code will print Hey until I don't press 'a' I want a code which can also erase the statement on screen
with explanation if possible
Can you clarify what you mean?
that code is given by you as you know that i used user defined function which will contonuosly print 'hey' repeat until i don't press 'a' and it will print 'bye'
but i want a code when i press 'a' it erase the 'hey'
Not very sure, but try this :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include<stdio.h>
#include<conio.h>

 void rep();
 int main()
 {
     clrscr();
     printf("Hey! Please press 'a' to exit...\n");
     rep();
     getch();
 }

 void rep()
 {
     printf("Hey\n");  
     if(!kbhit() || getch() != 'a') rep(); 
     clrscr(); printf("bye"); return;
 }
Does that help? :)
yeah :D thank you soo much again :)
you are awesome!
Glad it helped :)
Topic archived. No new replies allowed.