Open andrewdiep1 opened 4 months ago
I will code review this!
Update: I've learned that each person is expected to perform only one code review, so I won't be providing any further feedback on this code. (Your code looks great to me though.) I apologize for any inconvenience this may cause.
I will code review this too
I tried testing the program and here are the errors I found.
If I try to enter head or tail for something that is not a text file, it returns a really weird value .
For example: If I enter head mkdir
it returns this
Adding error checking to check if the file is a text file/file would help prevent the issue
Also if I enter head .
which is for a directory, it would return nothing. I think it would be useful to say something like head does not support directories
or potentially list the text files in the directory instead.
I also think if you enter head
, instead of saying Error: Needs Arguments
you could say something like Error: Needs <file> and optional<flags>
and print out what the helper flag has.
printf("ERROR: No valid files in any of the arguments.\n");
I also think for error checking instead of printing to STDOUT you can print to STDERR instead using fprintf(2, "ERROR: No valid files in any of the arguments.\n")
and exiting right after using exit 1
Also if enter two text files such as head small.txt totem.txt
it would only print out the small.txt file. I think you could say you do not support displaying multiple files at the moment or loop through each text file and print out the head/tail of its contents
I love how head and tail works and the ASCII art for the -f function. Great Job!
Hello! I think the code itself is great. I did not find any issues and what I am about to list is very subjective:
head -n 5 -c 10 small.txt
returns This is a
I would do the same for multiple input files as well.This looks great, I like the coin flip addition too :-)
The suggestions you got above are good, and shouldn't be too much work to implement.
One more change: usually with head or tail, you can pipe data into them, and they'll read from stdin
by default. That will make them both more useful (esp in pipelines). That shouldn't be more than a couple lines to support.
Nice work.
New Features:
This update introduces two new commands,
head
andtail
, for viewing file content easily.head
: Grabs the beginning part of a file, based on either bytes or lines.tail
: Retrieves the end part of a file, also by bytes or lines.Options:
-c
: Specify the number of bytes.-n
: Specify the number of lines.-v
: Shows the file name as it's being processed.-f
: Adds a fun twist: the command only works if it lands on the specified outcome in a coin flip (e.g.,head
lands on head,tail
lands on tail).-h
: Displays the usage of how to usehead
ortail
.Test files are included as the text files added in the commit!