Click here to Skip to main content
16,006,749 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Objective-C
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 !
Posted
Comments
Sergey Alexandrovich Kryukov 16-Jan-16 15:08pm    
This is not C. The code makes no sense. You have to learn some programming from scratch, that's it.
You need to start from the very beginning, learn what are variables, that they need to be declared/defined and initialized, and so on. You need to learn how to use command line and how it comes to your program. And so on...
—SA

1 solution

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!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900