Clear screen...

Hey I'm on a linux and I want help with deleting text... clear the screen no system();
Then color screen red...
Also how can the programmer tell how big the screen is(How many lines)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <stdio.h>
#define BG  "\033[7;31m"
#define TXT  "\033[0;37m"
#define CLEAR "\033[2k"
#define UP "\033[A"
void help();
void stupid();
void version();
int main(int argc, char* argv[])
{
if (argc!=2)
{
stupid();
return 1;
}
if (argv[1][0]=='-')
{
switch (argv[1][1])
{
case 'h':
help();
break;
case 'v':
version();
break;
case 'e':
return 1;
default:
stupid();
return 1;
}
}
else
{
int i=0;
while (i<30)
{
printf(UP);
printf(CLEAR);
printf(UP);
i++;
}
printf( BG "Hello, " );
printf( argv[1]);
printf( BG "!\n");
}
return 0;
}
void help()
{
printf("Usage:\n./hello [NAME] [-hv]\n");
printf("\t-h\tHelp\n");
printf("\t-v\tVersion\n");
}
void stupid()
{
printf("STUPID!\n");
printf("TYPE THE NAME OF THE PROGRAM THEN YOUR NAME.\n");
printf("IT ISN'T COMPLICATED!\n");
}
void version()
{
printf("Hello (C) 2013 Tim Palmer\n");
printf("Version: 0.0.2\n");
} 
Last edited on
Search these forums please.
I have that's how I got this far... But the CLEAR doesn't seem to work... it just takes cursor to the place up specifies
Your escape code is incorrect.

Here's something for you to play with. Just #include and go:
http://www.cplusplus.com/forum/general/18200/#msg92479

Also, learn to indent. It will help you understand your code a whole lot better.

Hope this helps.



[edit] Oh, yeah, you might want to do it right, since using VT-100 escape codes is error prone and not cross-platform:
http://www.cplusplus.com/forum/beginner/7303/#msg33713
Last edited on
If you have to, print 100 newlines, then CLEAR.
Last edited on
About indent I indent when on graphical ide but I'm using vi so it makes it harder
And I saw this before in a search
The link to cross platform escape codes... how do I use it?
About the comment
>You could just print 100 \n then CLEAR
How do I clear?
Last edited on
printf(CLEAR);
thank you I got everything except how big is the screen id like to clear only as many lines as the screen is tall...
You can indent just as easily in vim as any other text editor.

Ask stty size for the number of rows and columns. Some systems maintain $ROWS and $COLS as well.

If you are using the VT-100/ANSI escape codes to manipulate the screen, you don't need to care how many lines it has to clear it.
What is syntax for stty size??? And I am using ansi but what func will clear the whole screen...
All I have is
 
"\033[2K"
I found stty size... but if I want to find it in a program not at the shell...?
What is syntax for stty size???

Why not try it?
Or google it?
It took me all of about two seconds to look it up for you.

And I am using ansi but what func will clear the whole screen...
All I have is

"\033[2K"

Perhaps someday I'll see someone actually click a link I provided.

If you are going to ask a question, don't keep answering it before you look at the answers you are given.

ESC [2K doesn't clear the screen -- it clears the current line.

ESC [2J clears the screen and places the cursor in the home position.

I've given you enough help now. Good luck!
Thank you about ncurses I've tried but it doesn't work on android...
I think I've got every thing so thanks I saw on another post that you made a
PressAnyKey function where is it I couldn't find it...
I didn't realize you were on Android.

Here's something relevant about getting ncurses working on it:
http://credentiality2.blogspot.com/2010/08/compile-ncurses-for-android.html

And here's someone who has done all the dirty work for you:
https://github.com/CyanogenMod/android_external_libncurses


The press any key stuff is in this old article (that I still have to update):
http://www.cplusplus.com/articles/iw6AC542/
Scroll down to the unix section

If Android's terminal emulator is xterm compatible, the little .hpp I provided should work just fine.
Thanks I think everythings good
Hey
@duoas
On ncurses if I just have the .h files will that be fine? Do I need to install?
What .hpp???
Last edited on
*.h = c header. *.hpp = cpp header. AFAIK.
http://lmgtfy.com/?q=*.h+vs+*.hpp
sudo apt-get install ncurses-devel



I think... I don't use Android -- or Debian, for that matter.
Last edited on
Topic archived. No new replies allowed.