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

Skip to content

melaniereis/42_get_next_line

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

18 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌟 42_get_next_line

Animated Reading Line GIF

License Norminette

Overview β€’ Features β€’ Quick Start β€’ Examples β€’ Author

πŸ“– Project Overview

Click to expand

get_next_line is a crucial project in the 42 School curriculum, focusing on file I/O operations and static variables in C. This function allows you to read content line by line from a file descriptor, enhancing your understanding of:

  • File descriptors
  • Static variables
  • Memory allocation and management
  • Buffer handling

The main goal is to create a function that reads a line from a file descriptor each time it's called, returning the line that was read. If there's nothing else to read or if an error occurred, it should return NULL.

✨ Features

Core Functionality
  • Reads from any file descriptor (files, standard input, etc.)
  • Returns one line at a time
  • Handles multiple file descriptors simultaneously
  • Efficient memory management to prevent leaks
  • Graceful handling of various edge cases
Bonus Features
  • Uses only one static variable
  • Manages multiple file descriptors without losing the reading thread on each of them

πŸš€ Quick Start Guide

Installation Steps
  1. Clone the repository: bash git clone https://github.com/melaniereis/get_next_line.git cd get_next_line

  2. Compile the project: bash gcc -Wall -Wextra -Werror -D BUFFER_SIZE=32 *.c

  3. Include the header in your C file:

#include "get_next_line.h"

  1. Use get_next_line in your code:

char *line = get_next_line(fd);

πŸ’‘ Example Usages
Click to see code examples

#include "get_next_line.h" #include <fcntl.h> #include <stdio.h>

int main(void) { int fd = open("example.txt", O_RDONLY); char *line;

while ((line = get_next_line(fd)) != NULL)
{
    printf("%s", line);
    free(line);
}
close(fd);
return 0;

}

πŸ“ Project Structure
File Structure

text . β”œβ”€β”€ get_next_line.c # Main function implementation β”œβ”€β”€ get_next_line.h # Header file with function prototypes β”œβ”€β”€ get_next_line_utils.c # Utility functions └── Makefile # Compilation rules

πŸ“ Norminette Compliance This project adheres to the Norm, the coding standard of 42 School. All files pass the Norminette check, ensuring clean and maintainable code. πŸ§ͺ Testing
Test Files and Edge Cases To thoroughly test get_next_line, consider the following scenarios:
Empty files
Files with only newline characters
Files with no newline characters
Very large files
Files with long lines
Files with varying line lengths
Reading from standard input
Reading from multiple file descriptors

You can create test files or use existing text files to cover these cases.

πŸ‘©β€πŸ’» Author Melanie Reis
Contact Information

GitHub: @melaniereis
LinkedIn: Melanie Reis
πŸ“„ License This project is licensed under the MIT License - see the LICENSE file for details. πŸ™ Acknowledgments
Special thanks to 42 School for providing this project subject and guidelines.
Inspired by various C programming resources and best practices.
πŸ“š Additional Resources
C File I/O Tutorial
Understanding Static Variables in C
42 School Official Website

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published