1.输出修饰
我们已经通过一些例子看到了文字修饰(Attributes)的效果。给某些文字加上修饰会使文
字更加醒目和美观。在某些程度上也会增加输出信息的可读性。下面这个程序将会把一个C
语言的源程序文件的注释部分用粗体(BOLD)输出。
#include <ncurses.h>
int main(int argc, char *argv[])
{
int ch, prev;
FILE *fp;
int goto_prev = FALSE, y, x;
if(argc != 2)
{
printf("Usage: %s <a c file name>\n", argv[0]);
exit(1);
}
fp = fopen(argv[1], "r"); /* 在这里检测文件是否成功打开*/
if(fp == NULL)
{
perror("Cannot open input file");
exit(1);
}
initscr(); /* 初始化并进入curses 模式*/
prev = EOF;
while((ch = fgetc(fp)) != EOF)
{
if(prev == '/' && ch == '*') /* 当读到字符“/”和“*”的时候开启修饰*/
{
attron(A_BOLD); /* 将“/”和“*”及以后输出的文字字体加粗*/
goto_prev = TRUE;
}
if(goto_prev == TRUE) /* 回到“/”和“*”之