GithubHelp home page GithubHelp logo

pasqualerossi / 42-school-exam-rank-03 Goto Github PK

View Code? Open in Web Editor NEW
108.0 3.0 21.0 275 KB

2nd 42 School Exam

C 100.00%
42-exam 42exam 42exams exam-rank-02 exam-rank-03 42get-next-line 42gnl 42printf get-next-line get-next-line-1337

42-school-exam-rank-03's Introduction

Norminette

There's no norminette in this exam ๐Ÿ’ป

1 Exam Question

Either Get_Next_Line or Ft_Printf:

if you can make the code shorter, but readable, let me know!

Exam Practice Tool

Practice the exam just like you would in the real exam with this tool - https://github.com/JCluzet/42_EXAM

42-school-exam-rank-03's People

Contributors

agarraga avatar alexmitcul avatar chamdgeas avatar dumbrosio avatar ilovedefi avatar pasqualerossi avatar seozkan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

42-school-exam-rank-03's Issues

the signature of the function in the ft_printf.c repo is not correct

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!

This code does not work for GNL new instructions (Rome 42 campus, since May 2023)

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!

BUFFER_SIZE

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 ?

Order of variable (Get-next-line)

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);
}

Memory leak

  • At the first condition, you have to free buffer variable and then you can return

leaks in the code you provide

#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);

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.