|
| 1 | +Assignment name : get_next_line |
| 2 | +Expected files : get_next_line.c get_next_line.h |
| 3 | +Allowed functions: read, free, malloc |
| 4 | +-------------------------------------------------------------------------------- |
| 5 | + |
| 6 | +Write a function will store, in the parameter "line", a line that has been read from the file descriptor 0. |
| 7 | + |
| 8 | +Your function must be prototyped as follows: int get_next_line(char **line); |
| 9 | + |
| 10 | +Your function should be memory leak free. |
| 11 | + |
| 12 | +What we call a "line that has been read" is a succession of 0 to n characters that end with '\n' (ascii code 0x0a) or with End Of File (EOF). |
| 13 | + |
| 14 | +The string stored in the parameter "line" should not contained any '\n'. |
| 15 | + |
| 16 | +The parameter is the address of a pointer to a character that will be used to store the line read. |
| 17 | + |
| 18 | +The return value can be 1, 0 or -1 depending on whether a line has been read, when the reading has been completed (meaning read has returned 0), or if an error has happened respectively. |
| 19 | + |
| 20 | +When you've reached the End Of File, you must store the current buffer in "line". If the buffer is empty you must store an empty string in "line". |
| 21 | + |
| 22 | +When you've reached the End Of File, your function should keep 0 memory allocated with malloc except the last buffer that you should have stored in "line". |
| 23 | + |
| 24 | +What you've stored in "line" should be free-able. |
| 25 | + |
| 26 | +Calling your function get_next_line in a loop will therefore allow you to read the text available on a file descriptor one line at a time until the end of the text, no matter the size of either the text or one of its lines. |
| 27 | + |
| 28 | +Make sure that your function behaves well when it reads from a file, from the standard output, from a redirection etc. |
| 29 | + |
| 30 | +No call to another function will be done on the file descriptor between 2 calls of get_next_line. |
| 31 | + |
| 32 | +Finally we consider that get_next_line has an undefined behavior when reading from a binary file. |
| 33 | + |
| 34 | +You should use the test.sh to help you test your get_next_line. |
0 commit comments