GithubHelp home page GithubHelp logo

mohsink20 / get_next_line Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 8 KB

This project involves programming a function that returns a line read from a file descriptor. It not only adds a convenient function to your collection but also introduces the concept of static variables in C programming.

License: MIT License

C 100.00%
42 42born2code 42cursus 42projects 42school 42sg 42singapore getnextline getnextline-42 getnextline42

get_next_line's Introduction

Get Next Line

Reading a line from a file descriptor is way too tedious

Summary:

This project involves programming a function that returns a line read from a file descriptor. It not only adds a convenient function to your collection but also introduces the concept of static variables in C programming.

Contents

I. Goals
II. Common Instructions
III. Mandatory Part
IV. Bonus Part
V. Submission and Peer-Evaluation

I. Goals

This project aims to enhance your programming skills by implementing a function that efficiently reads lines from a file descriptor using static variables.

II. Common Instructions

  • Project must be written in C.
  • Follow the Norm for coding standards.
  • Functions should not quit unexpectedly, and memory must be properly managed.
  • Submit a Makefile for compilation.
  • Include basic Makefile rules: $(NAME), all, clean, fclean, and re.
  • To turn in bonuses, include a bonus rule in your Makefile.
  • If your project allows the use of libft, copy its sources and associated Makefile into a libft folder.
  • Encouraged to create test programs for self-testing and peer evaluation.

III. Mandatory Part

  • Function name: get_next_line
  • Prototype: char *get_next_line(int fd);
  • Turn in files: get_next_line.c, get_next_line_utils.c, get_next_line.h
  • Parameters: fd: The file descriptor to read from
  • Return value: Read line (correct behavior), NULL (no more to read or error)
  • External functs.: read, malloc, free
  • Description: Write a function that returns a line read from a file descriptor.
    • Repeated calls to get_next_line() should let you read the text file pointed to by the file descriptor, one line at a time.
    • Return the read line or NULL if there's nothing else to read or if an error occurs.
    • The returned line should include the terminating \n character, except if the end of the file was reached and does not end with a \n character.
    • Header file get_next_line.h must contain the prototype of the get_next_line() function.
    • Implement helper functions in get_next_line_utils.c.
    • Compile your code with the option -D BUFFER_SIZE=n to define the buffer size for read().

Note: get_next_line() has undefined behavior if the file changes since the last call, and it also has undefined behavior when reading a binary file.

IV. Bonus Part

Bonus Requirements:

  • Develop get_next_line() using only one static variable.
  • Manage multiple file descriptors simultaneously.
    • You should be able to read from different file descriptors without losing the reading thread of each or returning a line from another fd.
    • Files for bonus: get_next_line_bonus.c, get_next_line_bonus.h, get_next_line_utils_bonus.c

V. Submission and Peer-Evaluation

Turn in your assignment in your Git repository. Only the work inside your repository will be evaluated during the defense. Double-check file names for correctness. When writing tests, consider varying buffer and line sizes, and remember that a file descriptor does not only point to regular files. Cross-check with your peers and prepare a diverse set of tests for defense.

get_next_line's People

Contributors

mohsink20 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.