Write the `tail` program, in C, on the whiteboard.
Sigiloso
#include #include #include #define NUMBER_OF_LINES 10 char * tail_file(); int main () { char * text; text=tail_file(); printf("%s\n", text); free(text); return 0; } char * tail_file() { char character; char * tail=NULL; tail = (char *) malloc(sizeof(char)); void *abc; int num_lines=0,N_Lines_To_Print = NUMBER_OF_LINES; FILE *fd; // file open check if((fd = fopen("log.txt","r")) == NULL){ printf("Unable to open the file\n"); } // count the number of lines in the file. while(fread(&abc,1,1,fd)) { character =(char *)abc; if(character == '\n') num_lines++; } // get the value of the number of lines not to be printed fseek(fd,0L,SEEK_SET); if(num_lines > N_Lines_To_Print) num_lines -= N_Lines_To_Print; else num_lines = 0; // start printing the file while(fread(&abc,1,1,fd)){ character = (char *)abc; if(!(num_lines)) { strcat(tail, &character); // this line causes a segmentation fault //printf("%c",character); } else if(character == '\n') num_lines--; } return tail; }