Skip to content

Program a function that enables reading content line by line from a file descriptor.

License

Notifications You must be signed in to change notification settings

jotavare/get_next_line

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Linkedin 42

AboutHow to useMandatoryBonusNorminetteLicense

ABOUT

This project taught me how to read from a file descriptor and use static variables. This function retrieves a single line from a specified file descriptor. When called in a loop, get_next_line returns all the contents of the file, one line at a time until the end of the file is reached. Additionally, this function can be compiled with any buffer size specified.

HOW TO USE

1º - Clone the repository

git clone git@github.com:jotavare/get_next_line.git

2º - Enter the project folder

cd get_next_line/get_next_line

3º - Compile the mandatory or bonus files

The program should always be compiled with the flags below.

[Flags] -Wall -Wextra -Werror
[Mandatory] cc [Flags] main.c get_next_line.c get_next_line_utils.c
[Bonus] cc [Flags] main.c get_next_line_bonus.c get_next_line_utils_bonus.c

4º - BUFFER_SIZE can be specified at compilation to override the default BUFFER_SIZE

get_next_line should be able to compile with and without the -D BUFFER_SIZE=[SIZE] flag.

[Flags] -Wall -Wextra -Werror -D BUFFER_SIZE=[SIZE] 
[Mandatory] cc [Flags] main.c get_next_line.c get_next_line_utils.c
[Bonus] cc [Flags] main.c get_next_line_bonus.c get_next_line_utils_bonus.c

5º - Execution with one or multiple file descriptors/standard input

./a.out [text.txt]
./a.out [text1.txt] [text2.txt]

MANDATORY

  • Read from one file descriptor, one line at a time.
  • Needs to return the line that was read. If empty or error, return NULL.
  • Should work as expected reading from a file or standard input.
  • Returned line should include the terminating \n character, except if it's the end of the file and the line does not end with \n.
  • The get_next_line.h header file should include at least the get_next_line() function.
  • All adicional functions should be included in get_next_line_utils.c file, libft is not allowed.
  • To define the buffer size for read(), add the option to the compiled file -D BUFFER_SIZE=[SIZE].

BONUS

  • Use only one static variable.
  • Manage multiple file descriptors at the same time.
  • Bonus files should include a suffix _bonus.[c/h].

NORMINETTE

At 42 School, it is expected that almost every project is written following the Norm, which is the coding standard of the school.

- No for, do...while, switch, case, goto, ternary operators, or variable-length arrays allowed;
- Each function must be a maximum of 25 lines, not counting the function's curly brackets;
- Each line must be at most 80 columns wide, with comments included;
- A function can take 4 named parameters maximum;
- No assigns and declarations in the same line (unless static);
- You can't declare more than 5 variables per function;
- ...
  • 42 Norms - Information about 42 code norms. PDF
  • Norminette - Tool to respect the code norm, made by 42. GitHub
  • 42 Header - 42 header for Vim. GitHub

LICENSE

This work is published under the terms of Unlicense.