scndcorp
Available
Work
École 42 ParisStudent, École 42 project

Get Next Line: reading lines from a file descriptor in C

École 42 project: a C function that reads a line from a file descriptor across successive reads, preserving state between calls through a static variable.

École 42 Paris

Challenge

Read a file line by line from a file descriptor, without knowing the size of the lines or of the file in advance, while managing a buffer and the memory kept from one call to the next.

Impact

  • Reading a file line by line regardless of the line size
  • State preserved between calls through a static variable
  • Handling of the buffer, end of file and multiple descriptors

What was done

A function that reads in blocks (read) and keeps its state between the calls through a static variable to reconstruct each line, handling the buffer, the end of file and several descriptors at the same time.

Stack

The technologies used on this mission.

  • C
  • File descriptors
  • Buffer / read
  • Variables statiques

A similar project in mind?

Let's talk through your challenges and see how to turn your vision into maintainable, tested technical reality.