Skip to content

Latest commit

 

History

History

get_next_line

get_next_line

Reading a line from a fd is way too tedious



Summary

This project is about programming a function that returns a line read from a file descriptor.




Goals

This project will not only allow you to add a very convenient function to your collection, but it will also allow you to learn a highly interesting new concept in C programming: static variables.




Usage (Bonus included)

$ [CC] [CFLAGS] [your_main.c] get_next_line.c get_next_line_utils.c -o main.out
  • You need to include 'get_next_line.h' header into your c or header files.

Prototype

char *get_next_line(int fd);

Example

#include "get_next_line.h"
#include <stdio.h>
#include <fcntl.h>

int main(void) {
	int fd = open("test.txt", O_RDONLY);
	char *line = get_next_line(fd);
	printf("%s", line);
	// free(line);
	// close(fd);
	return (0);
}

------------------------ test.txt ------------------------
Hello World!

----------------------------------------------------------

>> ./main.out
Hello World!
>>