当前位置:首页 » 编程语言 » 简单行编辑程序c语言
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

简单行编辑程序c语言

发布时间: 2022-07-06 19:38:25

‘壹’ 怎样用c语言编出一个简单的程序

C语言写的程序 要想运行必须有一定的集成开发环境支持(建议VC6.0),然后在里面创建工程,再在工程 中创建一个C的源文件(如example.c),在里面添加你要写的代码,编译运行就OK了
你添加的代码,如简单的程序:
#include"stdio.h"

void main(){
printf("This is my first program\n");
}

‘贰’ c语言程序设计 简单的行编辑器

/*
c语言程序设计 简单的行编辑器
【要求】
(1) 设置一个简单的行编辑器,每行以回车结束
(2) 数据以文件形式存储
(3) 编辑器具有查找、替换、修改数据的功能

【备注】完全原创,编写时间:2010-7-13。请把所有的注释信息提取出来就可以写程序设计报告。
*/
#include <stdio.h> /*标准文件流操作,这里使用了fopen/fclose/fprintf/printf/scanf/gets函数*/
#include <stdlib.h> /*标准系统库,这里使用了malloc/free/exit*/
#include <string.h> /*标准字符串库,这里使用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; i < index; i++) {
t = t->next;
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 * string)
{
L * t = 0; U index = 0;
if(!string) return ;
t = lines;
while(t) {
index ++;
if(strstr(t->text , string)) printf("%d: %s", index, t->text );
t=t->next;
}/*end while*/
}/*end lookup*/

/*在一行文本中执行替换命令,把所有关键字替换为新关键字*/
void rpc(char * string, char * key, char * replacement)
{
char fine[szLINE], * x = 0, * y = 0, * z = 0;
int la = 0, lb = 0, r = 0;
if(!string || !key || !replacement) return ;
memset(fine, 0, szLINE);
x = string; y = fine;
/*首先记录新旧关键字长度*/
la = strlen(key);
lb = strlen(replacement);
do {
/*用指针逐个比较*/
r = memcmp(x, key, la);
if(r) {/*如果关键字不匹配则复制字符串*/
*y = *x;
x++; y++;
}else{/*如果关键字匹配则替换字符串*/
memcpy(y, replacement, lb);
x += la; y += lb;
}/*end if*/
}while(*x);
/*将替换完成的结果返回*/
memcpy(string, fine, szLINE);
}/*end rpc*/

/*全文替换*/
void replace(L * lines, char * string, char * replacement)
{
L * t = 0; U index = 0;
if(!string || !lines || !replacement) return ;
t = lines;
while(t) {
index ++;
if(strstr(t->text , string)) {
printf("[BEFORE] %d: %s", index, t->text );
rpc(t->text, string, replacement);
printf("[AFTER ] %d: %s", index, t->text );
}/*end if*/
t=t->next;
}/*end while*/
}/*end replace*/

/*根据行号插入一行新文本,如果行号小于零则将文本追加至链表尾*/
void insert(L ** lines, char * line, int index)
{
L * t = 0, * s = 0; int i = 0;
if(!lines || !line) return ;
/*首先为新文本分配一个链表节点*/
t = (L*)malloc(sizeof(L));
memset(t, 0, sizeof(L));
strcpy(t->text , line);
if(index == 0 || !*lines) {/*如果链表为空则以新节点为起点定义链表*/
t->next = *lines;
*lines = t;
return ;
}/*end if*/
s = *lines;
if(index > 0)/*如果行号为正整数,则将链表指针指向行号之前*/
for(i = 0; i < index-2; i++) {
if(!s->next ) break;
s = s->next ;
}/*next*/
else/*否则链表指针指向表尾*/
while(s->next ) s = s->next ;
/*end if*/
/*完成链表插入操作*/
if(s->next ) t->next = s->next ;
s->next = t;
}/*end insert*/

/*根据行号删除一行文本*/
void erase(L ** lines, U index)
{
L * a = 0, * b = 0, * c = 0;
if(!lines) return ;
/*index -1 表示目标行,index -2表示目标行的前一行*/
a = locate(*lines, index-2);
b = locate(*lines, index-1);
if(!b) return ;
if(a) /*如果前一行存在则删除目标行*/
a->next = b->next;
else/*否则表示表头删除*/
*lines = b->next ;
/*end if*/
/*释放内存*/
free(b);
}/*end erase*/

/*根据行号和新录入文本替换原有行*/
void edit(L * lines, char * line, U index)
{
L * t = locate(lines, index-1);
if(!t) return ;
if(line) strcpy(t->text , line);
}/*end edit*/

/*将文件整个装入链表*/
int load(L ** lines, char * file)
{
FILE * f = 0; char line[szLINE]="";
int total = 0;
if(!lines || !file) return 0;
clear(lines);/*首先清空链表*/
/*打开文件*/
f = fopen(file, "r");
if(!f) {
fprintf(stderr, "%s is bad.\n", file);
return 0;
}/*end if*/
/*逐行读入内存并插入表尾*/
while(!feof(f)) {
memset(line, 0, szLINE);
fgets(line, szLINE - 1, f);
insert(lines, line, -1);
total ++;
}/*end while*/
fclose(f);
fprintf(stderr, "[%s] %d lines loaded.\n", file, total);
/*返回总行数*/
return total;
}/*end load*/

/*将链表保存到指定的文本文件*/
int save(L * lines, char * file)
{
FILE * f = 0; L * t = lines;
int total = 0;
if(!lines || !file) return 0;
/*打开文件*/
f = fopen(file, "w");
if(!f) {
fprintf(stderr, "%s is bad.\n", file);
return 0;
}/*end if*/
t = lines;
while(t) {/*逐个文件写入*/
fprintf(f, "%s", t->text );
t = t->next ;
total ++;
}/*end while*/
fclose(f);
fprintf(stderr, "[%s] %d lines saved.\n", file, total);
/*返回总行数*/
return total;
}/*save*/

/*执行加载文本文件命令*/
void exec_load(L ** lines, char * line)
{
char cmd[szLINE] = "", file[szLINE] = "";
/*分析命令行,提取文件名*/
sscanf(line, "%s %s", cmd, file);
/*执行加载命令*/
load(lines, file);
}/*end exec_load*/

/*执行文本保存命令*/
void exec_save(L ** lines, char * line)
{
char cmd[szLINE] = "", file[szLINE] = "";
/*分析命令行,提取文件名*/
sscanf(line, "%s %s", cmd, file);
/*执行保存命令*/
save(*lines, file);
}/*end exec_save*/

/*执行文本查看命令*/
void exec_view(L ** lines, char * line)
{
char cmd[szLINE] = ""; U from = 0, to = 0;
/*分析命令行,提取目标要查看的起始行号和终止行号*/
sscanf(line, "%s %u %u", cmd, &from, &to);
/*如果起始行号和终止行号大小相反,则根据起始行号显示一页*/
if(to < from) to = from + 24;
/*执行查看命令*/
view(*lines, stdout, from, to);
}/*end exec_view*/

/*执行行数统计命令*/
void exec_count(L ** lines, char * line)
{
fprintf(stderr, "%d lines in mem.\n", view(*lines, 0, 0, 0));
}/*end count*/

/*执行文本追加命令*/
void exec_append(L ** lines, char * line)
{
char text[szLINE] = "";
/*在命令之后另起新行用于录入文本*/
gets(text); strcat(text, "\n");
/*执行文本追加命令*/
insert(lines, text, -1);
}/*end exec_append*/

/*执行文本插入命令*/
void exec_insert(L ** lines, char * line)
{
char cmd[szLINE] = "", text[szLINE] = ""; U index = 0;
/*从命令行提取目标插入点的行号*/
sscanf(line, "%s %d", cmd, &index);
/*在命令之后另起新行用于录入文本*/
gets(text); strcat(text, "\n");
/*执行文本插入命令*/
insert(lines, text, index);
}/*end insert*/

/*执行文本删除命令*/
void exec_erase(L ** lines, char * line)
{
char cmd[szLINE] = ""; U index = 0;
/*从命令行提取目标行号*/
sscanf(line, "%s %d", cmd, &index);
/*执行文本删除命令*/
erase(lines, index);
}/*end erase*/

/*执行文本编辑命令*/
void exec_edit(L ** lines, char * line)
{
char cmd[szLINE] = "", text[szLINE] = ""; U index = 0;
/*从命令行提取目标行号*/
sscanf(line, "%s %d", cmd, &index);
/*在命令之后另起新行用于录入文本*/
gets(text); strcat(text, "\n");
/*执行文本编辑命令*/
edit(*lines, text, index);
}/*end edit*/

/*执行文本检索命令*/
void exec_lookup(L ** lines, char * line)
{
char cmd[szLINE] = "", text[szLINE] = "";
/*从命令行提取关键字*/
sscanf(line, "%s %s", cmd, text);
/*执行文本检索命令*/
lookup(*lines, text);
}/*end lookup*/

/*执行在线帮助命令*/
void exec_help(L ** lines, char * line)
{printf("\tcommands:\n\thelp\n\tquit\n\
\tload [file.txt]\n\
\tsave [file.txt]\n\
\tview [from line] [to line]\n\
\tcount\n\
\tappend [return + text]\n\
\tinsert [line number] [return + text]\n\
\terase [line number]\n\
\tedit [line number] [return + text]\n\
\tlookup [text]\n\
\treplace [keyword] [replacement]\n");
}/*end help*/

/*执行文本替换命令*/
void exec_replace(L ** lines, char * line)
{
char cmd[szLINE] = "", text[szLINE] = "", key[szLINE]="";
/*从命令行提取新旧关键字*/
sscanf(line, "%s %s %s", cmd, key, text);
/*执行文本替换命令*/
replace(*lines, key, text);
}/*end replace*/

/*执行退出命令*/
void exec_quit(L ** lines, char * line){exit(0);}

/*行编辑命令执行函数,顺序与关键字表keywords一一对应*/
FUNC functions[CMDS]={
exec_quit, exec_help, exec_load, exec_save,
exec_view, exec_count, exec_append, exec_insert,
exec_erase, exec_edit, exec_lookup, exec_replace
};/*end functions*/

/*从行输入中识别关键字,相当于parse*/
int identified(char * command, char * key)
{
int ln = 0, r = 0;
if(!command || !key) return 0;
ln = strlen(key);
r = memcmp(command, key, ln);
return r==0;
}/*end identified*/

/*主函数*/
int main(int argc, char * argv[])
{
L * lines = 0; char line[szLINE]=""; int a = 0, b = 0, i = 0; FUNC fun = 0;
/*打印欢迎信息*/
printf("Welcome to LINE EDITOR V1.0\nCommand [help] is available.\n");
/*如果带主函数带参数,则可以用于打印帮助,或者根据该参数加载一个文本文件*/
if(argc > 1) {
a = strcmp(argv[1], "--help");
b = strcmp(argv[1], "/h");
if(a && b)
load(&lines, argv[1]);
else{
exec_help(0, 0);
return 0;
}/*end if*/
}/*end if*/
/*主命令循环*/
for(;;) {
/*命令提示符中间是表示当前载入的文档总共有多少行的意思*/
printf("\n<%d>", view(lines, 0, 0, 0));
/*从键盘输入一个命令行*/
memset(line, 0, szLINE);
gets(line);
/*根据命令行扫描关键词代码表,根据代码表取得执行函数的地址,再根据执行函数地址调用行编辑命令*/
for(i = 0; i < CMDS; i++) {
if(identified(line, keywords[i])) {
fun = functions[i];
(*fun)(&lines, line);
break;
}/*end if*/
}/*next*/
}/*next*/
return 0;
}/*end main*/

‘叁’ c语言编写一个程序,非常简单

(1)

#include"stdio.h"
#include"math.h"
intmain(intargc,char*argv[]){
floatm,r;
intn;
printf("Pleaseinput,. ");
if(scanf("%f,%d,%f",&m,&n,&r)!=3||m<0||n<0||r<0){
printf("Inputerror,exit... ");
return0;
}
printf("Interest:%.0f ",m*(pow(1+r,n)-1)*.8);
return0;
}

运行样例:

‘肆’ 如何编程如何用C语言编辑一些简单的程序

首先打开vs2013,发现有新建项目 和 打开项目 的选项,选择新建项目。
之后会有一个新建项目的界面,左侧有各种语言的编写环境,比如VB,VC#,VC++,如果编写C语言就选择VC++,因为c++基本兼容C语言。这时的项目不用添加后缀,这相当于一个大的工程。
选择好类型,写好项目名称之后点击确定。
点击下一步
这里比较关键。勾上空项目,不选的话因为程序会默认为你添加一些代码,用不上有时会编译出错。比较适合初学者。
这时已经新建好一个项目了,右键源文件添加新建项。
添加新建项之后命名,C语言的代码一定要修改后缀,将.cpp改为.c,向程序说明这时一个C语言代码。
写好代码后调试运行,如果没有写让程序停留的代码就不要直接按F5,你可以按ctrl+F5调试。
平时默认为Debug,如果开发完成一个程序后给别人使用就要选择Release版的调试,这样别人在没有vs的环境下也可以使用。

分享

‘伍’ C语言简单行编辑器

/*
c语言程序设计 简单的行编辑器
【要求】
(1) 设置一个简单的行编辑器,每行以回车结束
(2) 数据以文件形式存储
(3) 编辑器具有查找、替换、修改数据的功能

【备注】完全原创,编写时间:2010-7-13。请把所有的注释信息提取出来就可以写程序设计报告。
*/
#include /*标准文件流操作,这里使用了fopen/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; i < index; i++) {
t = t->next;
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 text);
t = t->next;
}/*end while*/
return index;
}/*end view*/

/*在当前文档中根据关键字进行搜索,并将搜索结果打印出来*/
void lookup(L * lines, char * string)
{
L * t = 0; U index = 0;
if(!string) return ;
t = lines;
while(t) {
index ++;
if(strstr(t->text , string)) printf("%d: %s", index, t->text );
t=t->next;
}/*end while*/
}/*end lookup*/

/*在一行文本中执行替换命令,把所有关键字替换为新关键字*/
void rpc(char * string, char * key, char * replacement)
{
char fine[szLINE], * x = 0, * y = 0, * z = 0;
int la = 0, lb = 0, r = 0;
if(!string || !key || !replacement) return ;
memset(fine, 0, szLINE);
x = string; y = fine;
/*首先记录新旧关键字长度*/
la = strlen(key);
lb = strlen(replacement);
do {
/*用指针逐个比较*/
r = memcmp(x, key, la);
if(r) {/*如果关键字不匹配则复制字符串*/
*y = *x;
x++; y++;
}else{/*如果关键字匹配则替换字符串*/
memcpy(y, replacement, lb);
x += la; y += lb;
}/*end if*/
}while(*x);
/*将替换完成的结果返回*/
memcpy(string, fine, szLINE);
}/*end rpc*/

/*全文替换*/
void replace(L * lines, char * string, char * replacement)
{
L * t = 0; U index = 0;
if(!string || !lines || !replacement) return ;
t = lines;
while(t) {
index ++;
if(strstr(t->text , string)) {
printf("[BEFORE] %d: %s", index, t->text );
rpc(t->text, string, replacement);
printf("[AFTER ] %d: %s", index, t->text );
}/*end if*/
t=t->next;
}/*end while*/
}/*end replace*/

/*根据行号插入一行新文本,如果行号小于零则将文本追加至链表尾*/
void insert(L ** lines, char * line, int index)
{
L * t = 0, * s = 0; int i = 0;
if(!lines || !line) return ;
/*首先为新文本分配一个链表节点*/
t = (L*)malloc(sizeof(L));
memset(t, 0, sizeof(L));
strcpy(t->text , line);
if(index == 0 || !*lines) {/*如果链表为空则以新节点为起点定义链表*/
t->next = *lines;
*lines = t;
return ;
}/*end if*/
s = *lines;
if(index > 0)/*如果行号为正整数,则将链表指针指向行号之前*/
for(i = 0; i < index-2; i++) {
if(!s->next ) break;
s = s->next ;
}/*next*/
else/*否则链表指针指向表尾*/
while(s->next ) s = s->next ;
/*end if*/
/*完成链表插入操作*/
if(s->next ) t->next = s->next ;
s->next = t;
}/*end insert*/

/*根据行号删除一行文本*/
void erase(L ** lines, U index)
{
L * a = 0, * b = 0, * c = 0;
if(!lines) return ;
/*index -1 表示目标行,index -2表示目标行的前一行*/
a = locate(*lines, index-2);
b = locate(*lines, index-1);
if(!b) return ;
if(a) /*如果前一行存在则删除目标行*/
a->next = b->next;
else/*否则表示表头删除*/
*lines = b->next ;
/*end if*/
/*释放内存*/
free(b);
}/*end erase*/

/*根据行号和新录入文本替换原有行*/
void edit(L * lines, char * line, U index)
{
L * t = locate(lines, index-1);
if(!t) return ;
if(line) strcpy(t->text , line);
}/*end edit*/

/*将文件整个装入链表*/
int load(L ** lines, char * file)
{
FILE * f = 0; char line[szLINE]="";
int total = 0;
if(!lines || !file) return 0;
clear(lines);/*首先清空链表*/
/*打开文件*/
f = fopen(file, "r");
if(!f) {
fprintf(stderr, "%s is bad.\n", file);
return 0;
}/*end if*/
/*逐行读入内存并插入表尾*/
while(!feof(f)) {
memset(line, 0, szLINE);
fgets(line, szLINE - 1, f);
insert(lines, line, -1);
total ++;
}/*end while*/
fclose(f);
fprintf(stderr, "[%s] %d lines loaded.\n", file, total);
/*返回总行数*/
return total;
}/*end load*/

/*将链表保存到指定的文本文件*/
int save(L * lines, char * file)
{
FILE * f = 0; L * t = lines;
int total = 0;
if(!lines || !file) return 0;
/*打开文件*/
f = fopen(file, "w");
if(!f) {
fprintf(stderr, "%s is bad.\n", file);
return 0;
}/*end if*/
t = lines;
while(t) {/*逐个文件写入*/
fprintf(f, "%s", t->text );
t = t->next ;
total ++;
}/*end while*/
fclose(f);
fprintf(stderr, "[%s] %d lines saved.\n", file, total);
/*返回总行数*/
return total;
}/*save*/

/*执行加载文本文件命令*/
void exec_load(L ** lines, char * line)
{
char cmd[szLINE] = "", file[szLINE] = "";
/*分析命令行,提取文件名*/
sscanf(line, "%s %s", cmd, file);
/*执行加载命令*/
load(lines, file);
}/*end exec_load*/

/*执行文本保存命令*/
void exec_save(L ** lines, char * line)
{
char cmd[szLINE] = "", file[szLINE] = "";
/*分析命令行,提取文件名*/
sscanf(line, "%s %s", cmd, file);
/*执行保存命令*/
save(*lines, file);
}/*end exec_save*/

/*执行文本查看命令*/
void exec_view(L ** lines, char * line)
{
char cmd[szLINE] = ""; U from = 0, to = 0;
/*分析命令行,提取目标要查看的起始行号和终止行号*/
sscanf(line, "%s %u %u", cmd, &from, &to);
/*如果起始行号和终止行号大小相反,则根据起始行号显示一页*/
if(to < from) to = from + 24;
/*执行查看命令*/
view(*lines, stdout, from, to);
}/*end exec_view*/

/*执行行数统计命令*/
void exec_count(L ** lines, char * line)
{
fprintf(stderr, "%d lines in mem.\n", view(*lines, 0, 0, 0));
}/*end count*/

/*执行文本追加命令*/
void exec_append(L ** lines, char * line)
{
char text[szLINE] = "";
/*在命令之后另起新行用于录入文本*/
gets(text); strcat(text, "\n");
/*执行文本追加命令*/
insert(lines, text, -1);
}/*end exec_append*/

/*执行文本插入命令*/
void exec_insert(L ** lines, char * line)
{
char cmd[szLINE] = "", text[szLINE] = ""; U index = 0;
/*从命令行提取目标插入点的行号*/
sscanf(line, "%s %d", cmd, &index);
/*在命令之后另起新行用于录入文本*/
gets(text); strcat(text, "\n");
/*执行文本插入命令*/
insert(lines, text, index);
}/*end insert*/

/*执行文本删除命令*/
void exec_erase(L ** lines, char * line)
{
char cmd[szLINE] = ""; U index = 0;
/*从命令行提取目标行号*/
sscanf(line, "%s %d", cmd, &index);
/*执行文本删除命令*/
erase(lines, index);
}/*end erase*/

/*执行文本编辑命令*/
void exec_edit(L ** lines, char * line)
{
char cmd[szLINE] = "", text[szLINE] = ""; U index = 0;
/*从命令行提取目标行号*/
sscanf(line, "%s %d", cmd, &index);
/*在命令之后另起新行用于录入文本*/
gets(text); strcat(text, "\n");
/*执行文本编辑命令*/
edit(*lines, text, index);
}/*end edit*/

/*执行文本检索命令*/
void exec_lookup(L ** lines, char * line)
{
char cmd[szLINE] = "", text[szLINE] = "";
/*从命令行提取关键字*/
sscanf(line, "%s %s", cmd, text);
/*执行文本检索命令*/
lookup(*lines, text);
}/*end lookup*/

/*执行在线帮助命令*/
void exec_help(L ** lines, char * line)
{printf("\tcommands:\n\thelp\n\tquit\n\
\tload [file.txt]\n\
\tsave [file.txt]\n\
\tview [from line] [to line]\n\
\tcount\n\
\tappend [return + text]\n\
\tinsert [line number] [return + text]\n\
\terase [line number]\n\
\tedit [line number] [return + text]\n\
\tlookup [text]\n\
\treplace [keyword] [replacement]\n");
}/*end help*/

/*执行文本替换命令*/
void exec_replace(L ** lines, char * line)
{
char cmd[szLINE] = "", text[szLINE] = "", key[szLINE]="";
/*从命令行提取新旧关键字*/
sscanf(line, "%s %s %s", cmd, key, text);
/*执行文本替换命令*/
replace(*lines, key, text);
}/*end replace*/

/*执行退出命令*/
void exec_quit(L ** lines, char * line){exit(0);}

/*行编辑命令执行函数,顺序与关键字表keywords一一对应*/
FUNC functions[CMDS]={
exec_quit, exec_help, exec_load, exec_save,
exec_view, exec_count, exec_append, exec_insert,
exec_erase, exec_edit, exec_lookup, exec_replace
};/*end functions*/

/*从行输入中识别关键字,相当于parse*/
int identified(char * command, char * key)
{
int ln = 0, r = 0;
if(!command || !key) return 0;
ln = strlen(key);
r = memcmp(command, key, ln);
return r==0;
}/*end identified*/

/*主函数*/
int main(int argc, char * argv[])
{
L * lines = 0; char line[szLINE]=""; int a = 0, b = 0, i = 0; FUNC fun = 0;
/*打印欢迎信息*/
printf("Welcome to LINE EDITOR V1.0\nCommand [help] is available.\n");
/*如果带主函数带参数,则可以用于打印帮助,或者根据该参数加载一个文本文件*/
if(argc > 1) {
a = strcmp(argv[1], "--help");
b = strcmp(argv[1], "/h");
if(a && b)
load(&lines, argv[1]);
else{
exec_help(0, 0);
return 0;
}/*end if*/
}/*end if*/
/*主命令循环*/
for(;;) {
/*命令提示符中间是表示当前载入的文档总共有多少行的意思*/
printf("\n

‘陆’ c语言 简单行编辑程序

你的这个要求是绝对不可能有人满足你的。因为你的这个要求已经远远不只是一个最简单的 C 语言源程序代码了,它至少可以看成是一个 C 语言大作业(是一个行编辑程序,类似 UNIX/Linux 系统的 vi 程序了)。
而且了,任何一个编程人员,即使他们的编程水平再高,但是他们也毕竟不是神,看到你的需求之后马上就能够直接编写出全部、且正确的程序源代码,还必须要保证能够马上运行出正确的结果。
因为在整个编写程序的过程中,在程序代码调试上所花费的时间通常要比编写程序代码所花费的时间多得多。
而且再说了,编写任何程序都必须要在自己的电脑上安装一个程序开发、调试环境,通过自己亲自上机编写程序、且通过自己的艰苦调试程序,最终调试出程序的正确运行结果。
以上就是我个人多年编程的亲身体会。

‘柒’ C语言 行编辑程序

/*TC2编译通过*/
/*以回车符为结束符输入一行*/
#include <stdio.h>
#define MAXSIZE 128

int main()
{
char base[MAXSIZE];
char *stack,*p;
char c;
stack=base;
while((c=getchar())!='\n')
{
if(c=='@') stack=base;
else if(c=='#'){if(stack!=base) stack--;}
else *(++stack)=c;
}
if(stack==base) printf("√");/*没有可输出的字符*/
p=base;
while(p!=stack) printf("%c",*(++p));
getch();
}

‘捌’ 求简单C语言程序代码!

输入2个正整数m和n,求其最大公约数和最小公倍数

#include

#include

int main()

int m,n,p,q,s,r;

printf("请输入两个正整数;m,n ");

scanf("%d,%d",&m,&n);

#include<stdio.h>

main()

int a,b,t=0;

scanf("%d %d",&a,&b);

if (a<b)

printf("%d %d %d %d %d",(a+b),(a-b),(a/b),(a*b),(a%b));

}

主要特点

C语言是一种结构化语言,它有着清晰的层次,可按照模块的方式对程序进行编写,十分有利于程序的调试,且c语言的处理和表现能力都非常的强大,依靠非常全面的运算符和多样的数据类型,可以轻易完成各种数据结构的构建,通过指针类型更可对内存直接寻址以及对硬件进行直接操作,因此既能够用于开发系统程序,也可用于开发应用软件。

以上内容参考:网络-c语言

‘玖’ 高分悬赏一C语言程序设计题(简单行编辑)

我有一个电话本程序似乎差不多喔,就差统计了。发给你看下,参考下吧。

#include <stdio.h>
#include <conio.h>
#define MAX 300
FILE *book;
char number[20],name[10];
main()
{
if((book=fopen("cell phone book.txt","a+"))==NULL)
{
printf("此为第一次运行。\n");
}
else
printf("电话本己打开。\n");
start();
fclose(book);
}
start()
{
int c;
int n=1;
do
{
printf("1·查找电话。\n");
printf("2·加入新电话。\n");
printf("3·显示整个电话本。\n");
printf("4·删除电话。\n");
printf("5·退出。\n");
c=getch();
printf("您选择了%c\n",c);

switch (c)
{
case '1':search();
break;
case '2':adser();
break;
case '3':print();
break;
case '4':del();
break;
case '5':n=0;
break;
default:
break;
}
}while(n!=0);
}
del()
{
char temp[30],name[10];
FILE *tempbook;
int n,p=0;
tempbook=fopen("temp.txt","w");
fclose(tempbook);
tempbook=fopen("temp.txt","a");
book=fopen("cell phone book.txt","r");
printf("输入要删除的人名。\n");
scanf("%s",name);
while(fgets(temp,MAX,book)!=NULL)
{
for(n=0;n<10;n++)
{
if(temp[n]!=name[n])
{
p=1;
break;
}
if(temp[n]==NULL)
break;
}
if(p==1)
{
fwrite(temp,2,5,tempbook);
fwrite(&temp[10],1,12,tempbook);
fwrite("\n",1,1,tempbook);
}
p=0;
}
fclose(tempbook);
fclose(book);
book=fopen("cell phone book.txt","w");
fclose(book);
book=fopen("cell phone book.txt","a");
tempbook=fopen("temp.txt","r");
while(fgets(temp,MAX,tempbook)!=NULL)
{
fwrite(temp,2,5,book);
fwrite(&temp[10],1,12,book);
fwrite("\n",1,1,book);
}
fclose(tempbook);
fclose(book);
}
search()
{
char tempbook[30],name[10],p=0;
int n=0;
book=fopen("cell phone book.txt","rt");
printf("输入要查找的姓名。\n");
scanf("%s",name);
while(fgets(tempbook,MAX,book)!=NULL)
{
if(tempbook[0]==name[0]&&tempbook[1]==name[1]&&tempbook[2]==name[2]&&tempbook[3]==name[3]&&tempbook[4]==name[4])
printf("%s%12s\n",tempbook,&tempbook[10]);
}
fclose(book);
}
adser()
{
book=fopen("cell phone book.txt","a+");
printf("请输入姓名:\n");
scanf("%s",name);
printf("请输入电话号码:\n");
scanf("%s",number);
fwrite(name,2,5,book);
fwrite(number,1,12,book);
fwrite("\n",1,1,book);
fclose(book);
}
print()
{
char c;
book=fopen("cell phone book.txt","rt");
do
{
c=fgetc(book);
putchar(c);
}while(c!=EOF);
fclose(book);
}

‘拾’ 急求数据结构题目:简单行编辑程序C语言

可以减少表的空余字段,减少拆表的必要,例如用户集合可以一条记录带有 admin: true 属性,其他不带有这个属性,而在关系数据库中这类带来大量空余字段的属性最好拆表。
PostgreSQL 打开 HStore 扩展后也可以实现这样的结构。
如果觉得 admin: true 的例子太简单,可以考虑下怎么储存 gemspec 的内容并让它可索引。