There's no norminette in this exam ๐ป
Either Get_Next_Line or Ft_Printf:
if you can make the code shorter, but readable, let me know!
Practice the exam just like you would in the real exam with this tool - https://github.com/JCluzet/42_EXAM
2nd 42 School Exam
There's no norminette in this exam ๐ป
Either Get_Next_Line or Ft_Printf:
if you can make the code shorter, but readable, let me know!
Practice the exam just like you would in the real exam with this tool - https://github.com/JCluzet/42_EXAM
Here are the new instructions for get_next_line in the rank 03 exam at 42 Rome:
"- 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).
'\n' should be included if there is one
When you've reached the EOF, you must store the current buffer in a char * and return it.
If the buffer is empty you must return NULL.
In case of error, you must return NULL.
In case of not returning NULL, the pointer should be free-able.
- Your program will be compiled with the flag -D BUFFER_SIZE=xx, which has to be used as the buffer size for the read calls in your functions.
Your program can be compiled with AND without the -D flag
Your function must be memory leak free
When you've reached the EOF, your function should keep 0 memory allocated with malloc, except the line that has been returned.
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 or either the text or one of its lines
Make sure that your function behaves well when it reads from a file, from the standard output, from a redirection, etc...
No call to another function will be done on the file descriptor between 2 calls of get_next_line.
We consider that get_next_line has an undefined behavior when reading from a binary file."
The instruction in bold is new compared to this current version.
Unfortunately, even after implementing a ifndef in the .h file in order to accommodate this new rule, the exam is consistently failed.
Some classmates have suggested that BUFFER_SIZE cannot be modified. Perhaps this can be a clue in solving why we are currently unable to pass this exam with the new rules?
Thanks a lot!
The subject tells "BUFFER_SIZE=xx, which has to be used as the buffer size for the read calls", but you use 10000 as the fixed size of the buffer. Is it authorized at the exam ?
#include <stdlib.h>
#include <unistd.h>
char *get_next_line(int fd)
{
int i = 0;
int rd = 0;
char character;
if (BUFFER_SIZE <= 0)
return (NULL);
char *buffer = malloc(100000); // check before the current BUFFER_SIZE and then malloc
while ((rd = read(fd, &character, BUFFER_SIZE - BUFFER_SIZE + 1)) > 0)
{
buffer[i++] = character;
if (character == '\n')
break;
}
buffer[i] = '\0';
if (rd == -1 || i == 0 || (!buffer[i - 1] && !rd))
return (free(buffer), NULL);
return (buffer);
}
Hello, your get_next_line solution is not working for us in the Exam rank 03 at 42 Prague.
Hi,
I think you i++ one time more line 24.
*on get_next_line.c
Line 26 shows this:
-int ft_printf(const char *format, ...)
but is not correct, as it should be
-int ft_printf(const char *format, ... )
with a space also AFTER the three dots.
I know it could be a small problem, even if your readme shows the real signature from the subject, but in the repo its wrong, and this wrong version also works in the 42 grademe program https://grademe.fr/ so its really a hidden error.
It is frustrating because today I gave the exam, and It would not specify that the problem was in the signature of the function, as it would show traces listing the tests so it made solving the issue really confusing.
As always, reading the subject in the minute details would have saved me and other from this frustrating situation, hope this helps a bit other students!
change the order of declaration varaible ( len before dst)
char *ft_strdup(const char *src)
{
size_t len = ft_strlen(src) + 1;
char *dst = malloc(len);
if (dst == NULL)
return (NULL);
ft_strcpy(dst, src);
return (dst);
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.