[b][red]This message was edited by the IsoDeathscar at 2002-7-1 15:44:16[/red][/b][hr]
Hi guys, I'm stuck with a linux c programming excersize,My proggie should work but it isn't:(, here's the excersize.
Write a program last that prints the last n lines of a text file, by n and the file name should be specified form command line input. By default n should be 5, but your program should allow an optional argument so that
last -n file.txt
prints out the last n lines, where n is any integer. Your program should make the best use of available storage.
ANd here is my code,
// Made by IsoDeathcar#include #include
int main(int argc, char *argv)
if (argc == 1)
fprintf(stderr,"Specify a file to read %s file
if (argc == 2)
lines = 5;
if (argc == 3)
lines = 0-atoi(argv);
buffer = (char*)malloc(lines*255*sizeof(char));
stream = fopen(string,"r");
strncpy(buffer+(255*i), buffer+(255*(i+1)), 255);
fgets(buffer+(255*lines-1), 255, stream);
I just keep getting a segmentation error and I've tried a lot of things, but still get tthe same error, can somone please help me out.