UgolinOlle / get_next_line

πŸ“– β€’ A function that reads lines from a file descriptor

Home Page:https://ugolin-olle.com/projets/school/get_next_line

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

get_next_line

fract-ol 42 project badge

42 School Project Language: C

A function that reads lines from a file descriptor.

Table of Contents

About

This project, "get_next_line," is part of the 42 School curriculum and focuses on reading a line from a file descriptor (such as a text file or standard input) using a function called get_next_line.

Usage

To use the get_next_line function in your C program, follow these steps:

  1. Clone this repository:
git clone https://github.com/your_username/get_next_line.git
  1. Include the get_next_line.h header file in your C file.
  2. Compile your program with the get_next_line function:
gcc -o your_program your_file.c get_next_line.c get_next_line_utils.c
  1. Here an example to use it:
#include "get_next_line.h"

int main() {
    int fd;
	char **res;

    fd = open("sample.txt", O_RDONLY);
    while ((res = get_next_line(fd)) > 0) {
        printf("%s\n", res);
        free(res);
    }
    close(fd);
    return (0);
}

Functionality

The get_next_line function reads a line from the specified file descriptor until it reaches a newline character ('\n') or the end of the file (EOF). It stores the line in a buffer and returns it as a string. The function is designed to be called in a loop to read multiple lines from a file.

Installation

To compile the get_next_line function, run the following commands:

make

This will generate the get_next_line.a executable, which you can link with your C programs as mentioned in the usage section. But if you wan't as library, you just need to uncomment this line:

@$(AR) $(NAME) $(OBJS)

And comment this line:

@$(CC) $(CFLAGS) -I $(HDRDIR) $(OBJS) -D BUFFER_SIZE=5 -o $(NAME)

Contributing

Contributions to this project are welcome. If you find any issues or want to improve the code, please feel free to open a pull request or issue.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

πŸ“– β€’ A function that reads lines from a file descriptor

https://ugolin-olle.com/projets/school/get_next_line

License:MIT License


Languages

Language:C 78.8%Language:Makefile 21.2%