Skip to content

A function written in C to read a file away, one \n at a time.

Notifications You must be signed in to change notification settings

rodsmade/Get_Next_Line-42sp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

get_next_line

This project introduces the concepts of static variables, dynamic memory allocation, file descriptors and macros while solving one simple task: that of using the Linux standard function read() to scan a file for single lines (i.e. strings of chars ending in a single trailing \n (new line character)).

Files

  • get_next_line.c function implementation

  • get_next_line_utils.c auxiliary functions (project requirement)

  • get_next_line.h header file

  • only_skin sample text file (also lyrical masterpiece) for testing purposes. File size: 6940 bytes; new line char count: 251.

  • main.c printing loop iterating over the file. calls get_next_line to fetch each line, then prints.

Run the program

On your terminal, make sure to be on the same level as the *.c files, then run the command:

gcc get_next_line_utils.c get_next_line.c main.c -D BUFFER_SIZE=42 -o get_next_line

Here BUFFER_SIZE determines the size of the buffer used to read the file (in other words, how manny chars shall be read at once with every read() call). To run the program, enter the following in the command prompt:

./get_next_line

You should expect to see the lyrics to Only Skin by Joanna Newsom printed in your terminal window. How cool is that?!

Ys album cover

Final note

If you're a 42 student struggling to understand this project, I got your back! Please refer to this Notion page that I wrote covering the general concepts related to this project and a practical to-do list of tasks to help you get started writing your own get_next_line! It's in Portuguese 🌵

Acelera — Get_next_line

About

A function written in C to read a file away, one \n at a time.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages