Code Monkey home page Code Monkey logo

get_next_line's Introduction

get_next_line

Usage

The primary objective of this project is to implement a get_next_line() that reads from an opened file, identified by its file descriptor (FD), and returns the next line of text, stopping at the first newline character "\n" encountered. This process continues until the End Of File (EOF) is reached or a "\0" is found. the get_next_line() will return each time a char *next_line, a variable that was allocated and should be freed by you after use to evoid leaks.

basic usage:

#include "get_next_line.h"
int main(void)
{
	int fd;
	fd = open("test.txt, O_RDONLY)", O_RDONLY);
	char *str = get_next_line(fd);
	printf("%s\n", str);
	free(str);
	str = NULL;
	return (0);
}

Compilation and Execution:

gcc -Wall -Wextra -Werror get_next_line.c get_next_line_utils.c <you_func>.c -D BUFFER_SIZE=<size> -o get_next_line

Remarks


The function is implemented in C on Linux. Upon each invocation, if the file remains open, the function remembers the position where the last newline was encountered and resumes reading from the next character.

Data Structures:

  • Linked List: Utilizes a linked list to store chunks of text read from the file in a buffer.
  • Control Structure: Employs a secondary structure to maintain references to the head and tail of the linked list, facilitating efficient data management. Data structure: single linked list with head and tail, where each node is a buffer of size BUFFER_SIZE.
  • In case last buffer include the mix of the end of current line and the beggining of the next one, the "cleanup" shift will be done in place(polish()), whithout additional allocations.
  • bonus part: Reading Many Files at Once

Testing

Test Implementation: A supplementary file, main_tester.c, has been created to test the functionality of the bonus feature. This file specifically tests reading from multiple files.

Included Test File: The project includes a test.txt file for testing purposes, that is included in the same folder, but feel free to test it with other files.

Compilation and Execution: To compile and run the test, use the following command:

gcc -Wall -Wextra -Werror get_next_line_bonus.c get_next_line_utils_bonus.c main_tester.c -o get_next_line

get_next_line's People

Contributors

talkashi1111 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.