Richard Ivanowich wrote:
>
> Hello all,
>
> I need some help. (new to c) I want to print strings at x,y cordinates on
> the screen. But without using ncurses.
Use curses. All other approaces puts you in deep whater once your
program is run from different kinds of terminals.
> Also how do i make text appear in colors.
Use curses.
If you absolutely do not which to use curses, then you can usually
change colors by sending the appropriate escape sequences. Most
terminals (including Linux console) accepts the standard ANSI escape
sequences.
<ESC>[3<n>m changes foreground color to color n
<ESC>[4<n>m changes background color to color n
<ESC>[<y>;<x>H moves the cursor
<ESC>[0m reset to normal text
---
Henrik Nordström
----- curses example
#include <curses.h>
int colors[]={
COLOR_WHITE,
COLOR_RED,
COLOR_BLUE,
COLOR_GREEN,
COLOR_YELLOW
};
int main(int argc, char **argv)
{
int i;
initscr();
start_color();
for(i=0;i<5;i++) {
init_pair(i+1, COLOR_BLACK, colors[i]);
}
for(i=1;i<=5;i++) {
attrset(i,NULL);
mvprintw(5+i, (5+i)*2, "Color %d");
}
getch();
endscr();
}
---- ansi escape example
#include <stdio.h>
int main(int argc, char **argv)
{
int i;
printf("\033[H\033[J");
for (i=0;i<5;i++) {
printf("\033[%d;%dH\033[3%dmColor %d",
5+i, (5+i)*2, i, i);
}
printf("\033[0m\n");
}
----