Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1309458
  • 博文数量: 268
  • 博客积分: 10698
  • 博客等级: 上将
  • 技术积分: 2867
  • 用 户 组: 普通用户
  • 注册时间: 2007-07-14 22:21
文章分类

全部博文(268)

文章存档

2012年(19)

2011年(13)

2010年(29)

2009年(26)

2008年(99)

2007年(82)

我的朋友

分类: C/C++

2008-09-16 22:55:20

myst_color.h myst_color.c :
http://blog.chinaunix.net/u1/43271/showart.php?id=1196083

2colors.c

/*  2colors.c 

 *  written by Myst Shen on Sep. 16, 2008.                             

 */

#include <stdio.h>
#include <ctype.h>
#include "myst_color.h"

int x, y, c, num;
NODE *h;
FILE *fp;
char *color1;
char *color2;

int main (int argc, char *argv[]){
  int j=0;
  if (argc != 3) {
    printf ("Illegal arguments.\n");
    exit(0);
  }

  if (!(isdigit(*argv[1]))) {
    printf ("The first argument should be a digit!\n");
    exit(0);
  }

  fp = fopen(argv[2],"r");
  if (!fp) {
    printf ("Sorry, cannot open this file !.\n");
    exit(0);
  }

  h = init(fp);
  color1 = rand_color(1);
  color2 = rand_color(0);

  p = h;
  while (1){
    if( p == NULL ) break;
    if (p->val == '\n') j=0;
    j++;
    if (j > atoi(argv[1])) {
      p->color = color1;
    }
    else {
      p->color = color2;
    }
    p = p->next;
  }

  print(h);
  return 0;
}



Makefile:

CC=cc

CFLAGS = -g -Wall -Wextra -ansi -pedantic -O3

OBJ = myst_color.o 2colors.o

2colors: $(OBJ)

        $(CC) $(CFLAGS) -o2colors $(OBJ)

myst_color.o: myst_color.h myst_color.c

2colors.o: myst_color.h 2colors.c

clean:

        rm -f 2colors myst_color.o 2colors.o

阅读(963) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~