Thanks to visit codestin.com
Credit goes to github.com

Skip to content

MahendraDani/head

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Head

Implementation of head(1) CLI utility from scratch in C++ following the Build Your Own Head Tool coding challenge.

Setting up locally

To setup and run this project locally, please follow the below steps:

Prerequisites

  1. C/C++ Compiler: Please make sure that you have a C/C++ compiler installed on your system, preferably gcc or clang.

  2. Install make:

If you are using Mac, and have Homebrew installed, use :

brew install make

Setup

  1. Clone the project on your machine.
git clone https://github.com/MahendraDani/head.git
  1. Build from source

First change directory, cd head, then

make

This command will build the project from source, and output the executable bin/cat.

To verify clean installation, try running:

./cchead data/text.txt

You should be able to see first 10 lines of the data/text.txt file printed on the console.

Usage

For usage, please read the man page of head(1)

  1. Read input from a file
./cchead file.txt
  1. Read from multiple files and concatenate
./cchead file1.txt file2.txt file3.txt
  1. Read from stdin
./cchead
  1. Show first n lines
./cchead -n4 file.txt
  1. Show first c bytes
./cchead -c4 file.txt

Testing

Although writing tests was not included in the challenge, any program to be called "production-ready" should and must be appropriately tested. So I wrote a few tests in shell scripts to test my code.

Much of the inspiration of writing tests is taken from the git project (as you can see from the names of test files :P) which has a lot of tests written in shell scripts.

This also forced me to learn about shell scripting, unit testing and much more, which is also essential in writing good software.

To run the test suite, simply run :

make test

If you want to specially run a particular test file:

tests/<test_script>.sh

Thanks!

About

Implementation of UNIX head(1) CLI utility

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors