Back

GitHub


Get_next_line

Summary

Is an individual project about creating a function that returns the next line from a file descriptor, without knowing its size beforehand. One of the goal of this project is to learn a highly interesting concept in C programming: static variables, and to gain a deeper understanding of allocations, whether they happen on the stack memory or in the heap memory, the manipulation and the life cycle of a buffer, the unexpected complexity implied in the use of one or many static variables.

char*
get_next_line(int fd)
{
	static char	*staticbuf;
	char		*line;

	if (fd < 0 || BUFFER_SIZE <= 0 || read(fd, 0, 0) < 0)
		return (NULL);
	staticbuf = ftread(fd, staticbuf);
	if (!staticbuf)
		return (NULL);
	line = findline(staticbuf);
	staticbuf = nextline(staticbuf);
	return (line);
}

Introduction

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

Mandatory part

Write a function that returns a line read from a file descriptor

Frobbiden

Bonus part

This project is straightforward and doesn’t allow complex bonuses. However, we trust your creativity. If you completed the mandatory part, give a try to this bonus part.

Here are the bonus part requirements: