一点头绪都没有,急救啊

chaoyue200811 2010-11-07 10:04:41
设计一个程序cuts ,他从标准输入读入数据,获取有第一个参数n和第二个参数m所限的定范围的数据(包括这两个字符),n和m都是整数。例如:
$ cuts 11 14
This is a test of cuts program(输入)
test(显示结果)

...全文
164 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
沭水河畔 2010-11-08
  • 打赏
  • 举报
回复

更正一个错误:

#include <stdio.h>
#define SIZE 256

int main(int argc, char *argv[])
{
char str[SIZE]={0};
char dst[SIZE]={0};
int n,m;

if(argc!=3)
{
printf("Usage: %s START END\n",basename(argv[0]));
exit(1);
}

n=atoi(argv[1]);
m=atoi(argv[2]);
fgets(str,SIZE,stdin);

n<1?n=1:n;
if(n>m)
{
n=n+m;
m=n-m;
n=n-m;
}

strncpy(dst,str+n-1,m-n+1);
puts(dst);
//printf("%d\n",3*5);
return 0;
}
沭水河畔 2010-11-08
  • 打赏
  • 举报
回复

#include <stdio.h>
#define SIZE 256

int main(int argc, char *argv[])
{
char str[SIZE]={0};
char dst[SIZE]={0};
int n=atoi(argv[1]);
int m=atoi(argv[2]);

if(argc!=3)
{
printf("Usage: %s START END\n",basename(argv[0]));
exit(1);
}

fgets(str,SIZE,stdin);

n<1?n=1:n;
if(n>m)
{
n=n+m;
m=n-m;
n=n-m;
}

strncpy(dst,str+n-1,m-n+1);
puts(dst);

return 0;
}
献丑了,当然还是建议楼主读读cut源码,那个更专业、健壮。
laoshizhuce 2010-11-08
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 lishanchao 的回复:]

引用 8 楼 laoshizhuce 的回复:
同求高手指点 怎么在http://www.gnu.org/software/coreutils/查找cut的源码
src目錄下面。
[/Quote]

麻烦再指点下 这个src目录在哪个链接下 谢谢
weifirst118 2010-11-08
  • 打赏
  • 举报
回复
七楼就是正解,不必要去找源码。
沭水河畔 2010-11-08
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 laoshizhuce 的回复:]
同求高手指点 怎么在http://www.gnu.org/software/coreutils/查找cut的源码
[/Quote]src目錄下面。
laoshizhuce 2010-11-08
  • 打赏
  • 举报
回复
同求高手指点 怎么在http://www.gnu.org/software/coreutils/查找cut的源码
laoshizhuce 2010-11-08
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 cangtiantiexue 的回复:]

ftp://ftp.gnu.org/gnu/coreutils/
难道是在这里找吗?
[/Quote]
是的

你下载一个coreutils的tar就可以
cangtiantiexue 2010-11-08
  • 打赏
  • 举报
回复
ftp://ftp.gnu.org/gnu/coreutils/
难道是在这里找吗?
laoshizhuce 2010-11-08
  • 打赏
  • 举报
回复
莫非指的是类似coreutils-8.1.tar.gz 这种?

脸红啊

主要是对coreutils不熟悉啊
bo_00 2010-11-08
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 laoshizhuce 的回复:]

引用 9 楼 lishanchao 的回复:

引用 8 楼 laoshizhuce 的回复:
同求高手指点 怎么在http://www.gnu.org/software/coreutils/查找cut的源码
src目錄下面。


麻烦再指点下 这个src目录在哪个链接下 谢谢
[/Quote]

http://ftp.gnu.org/gnu/coreutils/
freetstar 2010-11-07
  • 打赏
  • 举报
回复
lz自己多找找吧
xiaocai0001 2010-11-07
  • 打赏
  • 举报
回复
URL都给你了, 还不会找....
chaoyue200811 2010-11-07
  • 打赏
  • 举报
回复
不会找代码,告诉下步骤啊
freetstar 2010-11-07
  • 打赏
  • 举报
回复
对的,看cut的代码
xiaocai0001 2010-11-07
  • 打赏
  • 举报
回复
看看系统的cut命令是怎么实现的, 都有现成的源代码 http://www.gnu.org/software/coreutils/

23,128

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧