Welcome to my Get Next Line project!
🚀 Get Next Line (GNL) is a C function that reads a line from a file descriptor, making it easier to handle input from files or standard input one line at a time. This project demonstrates proficiency in file handling, dynamic memory management, and string manipulation, all essential skills for C programming.
- Efficiently reads lines from files or standard input.
- Manages dynamic memory allocation and cleanup.
- Adheres to the 42 School standards for project submissions.
*get_next_line
:Reads the next line from the file descriptor and returns it as a string.ft_read
: Reads data from the file descriptor into a buffer and appends it to the existing saved string until a newline is found or the end of the file is reached.cut_a_line
: Extracts a line from the saved string up to and including the newline character.cut_the_line
: Adjusts the saved string to remove the line that was just read, preparing it for the next call toget_next_line
.
To support the core functionality, several helper functions are implemented:
ft_strlen
: Calculates the length of a string.check_for_newline
: Check if the string contains a\n
.ft_strjoin
: Concatenates two strings into a new string.
To install Get Next Line, follow these steps:
Clone the repository:
git clone https://github.com/Abdalrhman-Olimat/get_next_line.git
Compile the code:
cc -Wall -Wextra -Werror -D BUFFER_SIZE=n get_next_line.c get_next_line_utils.c main.c
Once you've linked the library to your project, you can use get_next_line
to read and parse text files line by line. Here's an example of how to use get_next_line
:
#include "get_next_line.h"
int main(void)
{
int fd;
char *line;
fd = open("example.txt", O_RDWR);
if (fd < 0)
{
perror("Error opening file");
return (1);
}
while ((line = get_next_line(fd)) != NULL)
{
printf("%s", line);
free(line);
}
close(fd);
return (0);
}
}
This will read the file example.txt
line by line and print each line to the console.
Contributions are welcome! If you have suggestions for improvements or new features, feel free to open an issue or submit a pull request.
If you have any questions or suggestions, please reach out to me via or