Skip to content

Develop a function that returns a row read from a file descriptor.

Notifications You must be signed in to change notification settings

FlorentBelotti/42_cursus_Gnl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 

Repository files navigation

42_cursus_get_next_line---------------------------------------------------

C

Table of Contents---------------------------------------------------

Introduction---------------------------------------------------

This project aims to develop a function that returns a line read from a file descriptor. It will help you learn about static variables in C and add a useful function to your collection.

Common Instructions---------------------------------------------------

  • The project must be written in C and conform to the coding norm.
  • Functions should not stop unexpectedly (segmentation fault, bus error, etc.) except for undefined behaviors.
  • All heap-allocated memory must be properly freed when necessary. No leaks will be tolerated.
  • A Makefile must be provided, compiling the source files with appropriate flags and not relinking.
  • The Makefile must contain at least the rules: $(NAME), all, clean, fclean, and re.

Mandatory Part---------------------------------------------------

Implement the function get_next_line() that reads a line from a file descriptor.

  • Function name: get_next_line
  • Prototype: char *get_next_line(int fd);
  • Files to turn in: get_next_line.h, get_next_line.c, get_next_line_utils.c
  • Parameters: fd - The file descriptor to read from
  • Return value: The line read, or NULL if nothing else to read or an error occurred
  • External functions allowed: read, malloc, free

Details---------------------------------------------------

  • Successive calls to get_next_line() should read the entire text file, one line at a time.
  • The function should return the line read followed by a newline, unless the end of the file is reached and it does not end with a newline.
  • The get_next_line.h header file must contain at least the prototype of the function.
  • The get_next_line_utils.c file should contain any additional helper functions required for get_next_line().
  • Your program must compile with the option -D BUFFER_SIZE=n to specify the buffer size for read() calls.

Bonus Part---------------------------------------------------

For those who complete the mandatory part perfectly, you can implement the following bonuses:

  • Implement get_next_line() using a single static variable.
  • Allow get_next_line() to handle multiple file descriptors simultaneously without losing track of each file descriptor's content.

Bonus files should have the suffix _bonus.[c|h] and include:

  • get_next_line_bonus.c
  • get_next_line_bonus.h
  • get_next_line_utils_bonus.c

About

Develop a function that returns a row read from a file descriptor.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages