编写程序。
1、实现新建程序。
2、编辑文件。
编辑命令包括
L n 显示第n行
D n 删除第年行
CU n m 将第n行复制到第m行上面
CD n m 将第n行复制到第m行下面
RA str1 str2 将文件中的所有str1用str2替换
R x y n str1 str2将文件中的第x行,第y列开始的n个字符中的所有str1用str2替换。
I x y str 在第x行,第y列字符前插入str
DAStr str 删除将文件中的所有str
DStr x y n str 删除文件中的第x行,第y列开始的n个字符中的所有str。
万分感谢。
运行程序并查看命令列表
打开文件并显示内容
将所有小写字母 a
更改为 A
退出和其他功能展示
今天下午想回答你那个有积分的回答,但是写到一半浏览器崩了~在刷新看到了有人已经在要采纳了~我就没有重新写了
1.1 fileIO流的实现
1.2 存储每行的文本内容
1.3 对文本内容进行处理(删除/追加等)
2.1 识别命令(L D等等)
2.2 识别命令后面的参数 (n 字符串str等等)
2.3 根据识别到对应命令后执行对应的操作
题目中有9个要求,那么也就是说你可以写成九个函数;
例如 R这个命令你就可以将这所有的操作写到一个名为replace(int startLine,int startRow,int lengh,char* desStr,char* srcStr);
这个函数中
那么当需要执行R 操作时对应调用参数就好啦;
如何操纵IO流文件这个可以寻求百度的帮助~
如何解析字符串将其装换为命令你可以使用 scanf来做,其实sscanf更加好一些,如果你了解scanf,那么你可以尝试使用sscanf;
如果你的水平还不错,或者你认为你其实可以实现这里的所有功能,那么你可以使用我的两个模块,他会帮助你更快的完成目标
1. 字符串调用函数模块,可以像linux命令行一样调用对应函数 类似于 add 3 4 //will show "7"
Github网址: https://github.com/KimAlittleStar/ExternFunc
教程网址: https://blog.csdn.net/qq_39575645/article/details/103867598
软件要自己写才有成就感哦.你可以百度各种小问题如何解决然后拼凑到一起组成你自己的成果~~
尝试自己解决每一个小问题才是一个合格的coder;
如果实在不会的话留言评论我~我如果周末有时间就写一下发在博客里;
但是也不一定会写哦~毕竟都是爱好;
如果我写了要个点赞关注不过分吧? [滑稽]
几个功能函数:
char text[100][256];
int count = 0;
void str_replace(char * cp, int n, char * str)//替换字符串
{
int lenofstr;
char * tmp;
lenofstr = strlen(str);
//str3比str2短,往前移动
if (lenofstr < n)
{
tmp = cp + n;
while (*tmp)
{
*(tmp - (n - lenofstr)) = *tmp; //n-lenofstr是移动的距离
tmp++;
}
*(tmp - (n - lenofstr)) = *tmp; //move '\0'
}
else
//str3比str2长,往后移动
if (lenofstr > n)
{
tmp = cp;
while (*tmp) tmp++;
while (tmp >= cp + n)
{
*(tmp + (lenofstr - n)) = *tmp;
tmp--;
}
}
strncpy(cp, str, lenofstr);
}
char s4[256];
char *insert(char *s1, char *s2, int n)//插入字符串
{
int len1 = 0, len2 = 0, j = 0, len3, k = 0;
int i;
char *s3 = s4;
if (s1 == NULL)
return NULL;
if (s2 == NULL)
return s1;
len1 = strlen(s1);
len2 = strlen(s2);
if (n > len1)
return NULL;
for (i = 0; i < n; i++)
{
j++;
}
for (i = 0; i < len1; i++)
{
s4[k++] = s1[i];
}
for (i = 0; i < len2; i++)
s1[j++] = s2[i];
for (i = n; i < len1; i++)
s1[j++] = s4[i];
s1[j] = '\0';
return s1;
}
char d[256];
void DeletS(char *s1, const char *s2){//删除字符串
char *p = s1, *q, *c;
unsigned long n = strlen(s2);
while (1) {
q = strstr(p, s2);
if (q == NULL)
break;
c = q + n;
*q = '\0';
strcpy(d, c);
p = strcat(p, d);
}
}