tail -c命令linux,用c实现 [英] tail -c command linux, implement with c

查看:130
本文介绍了tail -c命令linux,用c实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我尝试为linux实现tail -c命令,我必须从文件中打印最后n个字节,这是我的代码,不要去,不知道怎么做do

Hi,
I try to implement tail -c command for linux, I must to print last n bytes from a file, this is my code,and do not go, do not know how to do

void tail_c()
{
	numberOfByte=atoi(params[2]);
	numberOfByteShow=sizeof(file_name)-numberOfByte;
	file_name=params[3];
	if((status=open(file_name,O_RDONLY))==-1)
	{
		perror("Error");
	}
	else
	{
		buf=(char*)malloc(sizeof(char)*(SIZE+1));
		lseek(status,0L,SEEK_CUR);
		if((n=read(status,buf,SIZE))!=SIZE)
			printf("%s", buf);
	}			
			
	

        close(status);
}



谢谢!


Thanks !

推荐答案

所以使用调试器,看看究竟发生了什么:在函数的第一行放置断点,然后逐步查看每行的变量发生了什么。将其与您预期的生产线进行比较!



当您找到一些您没想到的东西时,请问问自己为什么。当你知道的时候,你可能已经找到了你的问题。



这是一项技能 - 称为调试 - 而且你唯一能做到这一点的原因就是这样做(像所有技能)。所以试一试看看你能找到什么!



但是不要去没有告诉任何人!
So use the debugger and see exactly what is going on: put a breakpoint on the first line in the function, and step through, looking at exactly what is happening to your variables at each line. Compare that to what you expected the line to do!

When you find something you didn't expect, ask yourself why. When you know that, you probably have found your problem.

This is a skill - called debugging - and the only why you get to be any good at it is by doing it (like all skills). So give it a try and see what you can find out!

But "do not go" tells nobody anything!


这篇关于tail -c命令linux,用c实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆