简单的行编辑器 【要求】 (1) 设置一个简单的行编辑器,每行以回车结束 (2) 数据以文件形式存储 (3) 编辑器具有查找、替换、修改数据的功能 2011-7-9。请把所有的注释信息提取出来就可以写程序设计报告。 #include /*标准文件流操作,这里使用了open/fclose/fprintf/printf/scanf/gets 函数*/ #include /*标准系统库,这里使用了 malloc/free/exit*/ #include /*标准字符串库,这里使用 strlen/strcpy/memcpy/memset*/ #define szLINE 252 /*定义一行字符串最长为 252 字节*/ #define CMDS 12 /*定义 12 个标准行编辑命令*/ /*采用链表存储文本*/ typedef struct LINE { char text[szLINE]; /*文本内容*/ struct LINE * next; /*链表指针*/ }L; /*简写无类型整数*/ typedef unsigned int U; /*定义 12 个行编辑命令的标准格式*/ typedef void (*FUNC)(L **, char*); /*定义 12 个标准行编辑命令的关键字*/ char keywords[CMDS][8]={ "quit", "help", "load", "save", "view", "count", "append", "insert", "erase", "edit", "lookup", "replace" }; /*end keywords*/ /*清空链表操作*/ void clear(L ** lines) { L *a =0, *b=0; if(!lines) return ; a = *lines; while(a) { b=a->next ; free(a); a=b; } /*end while*/ *lines=0; } /*end clear*/ /*在链表中根据行号 index 调出指定的行*/ L *locate(L *lines, U index) { L *t=lines; U i = 0; if(!t) return 0; if(index == 0) return t; for(i=0; inext; if(!t) return 0; }/*next*/ return t; }/*end locate*/ /*浏览命令,如果f 存在则以带行号格式保存文件(如果f==stdout 则打印到屏幕上),浏览范围为from 到to(行号)。view(lines, 0, 0, 0)表示统计已加载到内存的文本行数量*/ int view(L * lines, FILE * f, U from, U to) {L *t=lines; U index=0; while(t) { index ++; if(f && index >= from && index <= to) fprintf(f, "%d: %s", index, t->text); t=t->next; }/*end while*/ return index; }/*end view*/ /*在当前文档中根据关键字进行搜索,并将搜索结果打印出来*/ void lookup(L * lines, char * str...