Did this pass as is? I have a similar approach but I get errors with Francinette. Fsoares test read_error.txt claims there's memory leaks. Which I can see there are with valgrind. The variable returned by get_next_line() is malloc'd but never freed. Did u get similar errors with Francinette. I'm quite sure my code works, but I don't want to submit and get a fail.
Hey manuel, i used only this one github.com/Tripouille/gnlTester by which all tests are ok, also no Leaks. In my cluster we only used this one, i also passed the exam with this approach, frankly i dunno i definitely shall try this tester, maybe there are some corner cases i didn t check for 🤨.
@@onaecO I tested with valgrind and get some memory leaks. I guess that's whats flagged as error by Francinette. Though, in my own testing, I took care to properly free() the returned lines and had no issue. If you find no problem I guess I'll just push and hope for the best.
@@onaecO I ran my own test on the exact file that is returning error in Francinette. I applied valgrind and discovered that, if no free() was used, there were, in fact, memory leaks. So, in mine main.c file, inside the while loop, I added a free() to the returned pointer of each call of get_next_line(). This resulted in no more memory leaks detected by valgrind. Which might mean that it is the francinette test itself that's wrong. But I am not sure. This is how I wrote it: line = get_next_line(fd); while (line != NULL) { printf("%s", line); free(line); line = get_next_line(fd); } Without that free(), valgrind detects memory leaks. Right now this is the only idea I have on why it returns errors for these Francinette tests. Cause the output to console I'm seeing on my own trials is perfect. But I might be missing something.
perfect tutorial u did it the hard way for us as beginners using linked list but it's okay the important thing is that i got the full idea of what i need to do, much love 🙏
thanks oceano good explanation, the only thing i cannot understand is why in the while condition of the void create_list function. the subfunction found_newline finds 1 means there is ' ', so by logic it should stop the condition and not copy the last list which contains the ' ', but in your explanation it copy everything, where i misunderstood?
Hi, Oceano first thanks, for this crazy tutorial hahahah😅 so what should I return in this project: the line before we reach the null terminator '\0' and include the null terminator or return the line(lines) after the '\0' until the EOF
Hey ! Thanks a lot for your vidéo, it helps a lot to understand more ! For dealloc function, why did you free buf only if clean node is NULL ? And not in any case ? And why do you bring it to dealloc and don't free it directly in polish ?
Hello Cecile! I try to remember what i wrote 🤣 Here i say: “if str_buf contains at least 1 char, make this node the new head for next call to gnl” else “clean the buffer and the node” if (clean_node->str_buf[0]) *list = clean_node; else { free(buf); free(clean_node); } So if the buffer is empty, i don’t need it. Of course this is bad design code (i already feel cringe for old code 🤣), i could have used only clean_node struct that already contains the buffer, if i correctly recall my code. So i don’t free in every case simply because if there is a string inside buf, i’ll need the at the next gnl call. Polish is a special function to clean the linked list last node up to , so i decided to keep the clean up deallocs in another function. I hope i responded u!
@@onaecO Thank you so much for you answer ! I think now it's more clear for me : - buf and clean_node->str are pointing the same adress so if you clean buf you clean somehow clean_node->str too ? And don't be ashamed of your code : for beginners like me it's dynamite seriously ! 😂👌
Thx for the video=) Despite on I've made a project, there was a bunch of interesting information. One question: which IDE do you use. And could you pls share some basic settings of your .vimrc file? I see that you have autocomplete option in it. And, honestly, I don't know how to switch it on. Many thx in advance.
Bro, Thx for the comment! As you know these files are super tedious to decipher..i should properly make a video about. Anyway most ideas you can get from here ~th-cam.com/video/gnupOrSEikQ/w-d-xo.html this is the actual file, feed this to GPT + video and i think wont be super hard vimrc syntax on set number set tabstop=4 set shiftwidth=0 set backspace=indent,eol,start filetype plugin on call plug#begin('~/.vim/plugged') Plug 'davidhalter/jedi-vim' Plug 'sheerun/vim-polyglot' Plug 'nvie/vim-flake8' Plug 'tpope/vim-commentary' Plug 'neoclide/coc.nvim', {'branch': 'release'} Plug '42Paris/42header' Plug 'octol/vim-cpp-enhanced-highlight' "Plug 'ycm-core/YouCompleteMe', {'do': 'python3 install.py --clangd-completer'} "Plug 'valloric/youcompleteme' Plug 'vim-syntastic/syntastic' Plug 'preservim/nerdtree' Plug 'pboettch/vim-cmake' Plug 'ryanoasis/vim-devicons' Plug 'tiagofumo/vim-devicons-colorschemes' Plug 'vim-airline/vim-airline' Plug 'vim-airline/vim-airline-themes' " Python development plugins call plug#end() let g:jedi#force_py_version = 3 let g:jedi#auto_complete = 1 let g:jedi#show_docstring = 1 let g:jedi#show_call_signatures = 1 let g:jedi#auto_completion_start_timeout = 0 let g:jedi#auto_complete_delay = 0 let g:jedi#auto_complete_trigger_length = 1 " Set the Airline theme let g:airline_theme='onedark' "Automatic nerdtree map :NERDTreeToggle " "colors devicons "colorscheme murphy "DEBUG HIGHLIGHT highlight DEBUG ctermfg=black ctermbg=yellow guifg=black guibg=yellow "vim no split nnoremap :edit "COC stuff " Use the clangd language server for C and C++ let g:coc_global_extensions = ['coc-clangd'] " Enable completion for C and C++ "autocmd FileType c,cpp inoremap " \ pumvisible() ? "\" : " \ check_back_space() ? "\" : " \ coc#refresh() "function! s:check_back_space() " let col = col('.') - 1 " return !col || getline('.')[col - 1] =~ '\s' "endfunction " Enable diagnostics (errors and warnings) let g:coc_global_extensions = ['coc-clangd', 'coc-diagnostic'] " Show diagnostics in the sign column autocmd CursorHold * silent call CocActionAsync('diagnosticRefresh') autocmd CursorHoldI * silent call CocActionAsync('diagnosticRefresh') "Enter to select suggestion inoremap pumvisible() ? "\" : "\" " Use a lighter sign column highlight SignColumn ctermbg=NONE highlight SignColumn guibg=NONE " Configure coc-clangd let g:coc_clangd_binary = 'clangd' " Path to clangd binary let g:coc_clangd_args = ['-header-insertion=never'] " Arguments for clangd " Define the color for C warnings highlight cWarn ctermfg=red guifg=red " Set the syntax highlighting for C warnings autocmd Syntax c syn keyword cWarn contained warning " Set the color of diagnostic error messages highlight CocErrorSign ctermfg=white ctermbg=red guifg=#ffffff guibg=#ff0000
@@onaecO By the way... I don't know if you like it, but I was a bit disgusted about warning style icon in Coc (that ridiculous triangle with exlamation mark inside). So I've changed the rule a little bit=))) " Set warning color and sign highlight CocWarningSign guifg=red ctermfg=red let g:coc_user_config = { \ 'diagnostic': { \ 'warningSign': '!!' \ } \} Now it looks much prettier=)
The thing is that BUFFER_SIZE is a macro defined at compile time, it can be 1 , 42, 1 million, whatever. If you check my code i have in the .h file github.com/suspectedoceano/get_next_line/tree/main you find this # ifndef BUFFER_SIZE # define BUFFER_SIZE 10 # endif Just in case the value is not provided during compilation. Hardcoding 10 misses the point of the exercise, i.e. handling whatever buffer size. I hope i answered u ;)
@@onaecO ohhhhh so the reason why we marcro defined is because we can change all of it instantly without having to keep chaning all the variable one by one.
@@thebestteacher7466 Bingo! that’s exactly why they are useful. This “refactor the code” instantly. The more variables & constants , the better the code. Hard type values is bad, search for “magic numbers code”. Good work!
I am a huge fan, and I always follow you.. But I am really sorry to tell you that this video made the task even harder for a beginner. the fact you are using linked lists approach while beginners just got introduced to the linked lists in the bonus part of libft and they havent even properly used it and got handy with it, would definitely make me not suggest this video for a beginner. Sorry, and keep it up. cheers!
Never seen such a complicated explaination on this topic try to switch not to much and keep your focus on the subject. I have seen this video and compared to other things on the internet this seem like higher math.
th-cam.com/video/-Mt2FdJjVno/w-d-xo.html great video on this topic checkout his explanation he really keeps it onsubject and leaves out the unnecessary stuff
if you read the description , i had already mentioned the video. I just wanted to add smtg to that explanation , failing as i see Thx again for feedback
Actually, I found your explanation and code quite understandable and useful. I decided to stick to your approach to this problem. Thank you sirrr :)@@onaecO
Agree! Indeed this is me trying to “fuck around to get it done” back when I was a student, If I look back to my code I 🙈🙈🙈. Frankly I never expected many views, this channel was me just training on explaining things
Did this pass as is? I have a similar approach but I get errors with Francinette. Fsoares test read_error.txt claims there's memory leaks. Which I can see there are with valgrind. The variable returned by get_next_line() is malloc'd but never freed. Did u get similar errors with Francinette. I'm quite sure my code works, but I don't want to submit and get a fail.
Hey manuel, i used only this one
github.com/Tripouille/gnlTester
by which all tests are ok, also no Leaks. In my cluster we only used this one, i also passed the exam with this approach, frankly i dunno i definitely shall try this tester, maybe there are some corner cases i didn t check for 🤨.
@@onaecO I tested with valgrind and get some memory leaks. I guess that's whats flagged as error by Francinette. Though, in my own testing, I took care to properly free() the returned lines and had no issue. If you find no problem I guess I'll just push and hope for the best.
what do you mean by properly free?
come in the server a guy had a similar problem ;) discord.gg/2myeyu8v
@@onaecO I ran my own test on the exact file that is returning error in Francinette. I applied valgrind and discovered that, if no free() was used, there were, in fact, memory leaks.
So, in mine main.c file, inside the while loop, I added a free() to the returned pointer of each call of get_next_line(). This resulted in no more memory leaks detected by valgrind.
Which might mean that it is the francinette test itself that's wrong. But I am not sure.
This is how I wrote it:
line = get_next_line(fd);
while (line != NULL)
{
printf("%s", line);
free(line);
line = get_next_line(fd);
}
Without that free(), valgrind detects memory leaks. Right now this is the only idea I have on why it returns errors for these Francinette tests. Cause the output to console I'm seeing on my own trials is perfect.
But I might be missing something.
again a very helpful video!
perfect tutorial u did it the hard way for us as beginners using linked list but it's okay the important thing is that i got the full idea of what i need to do, much love 🙏
Ty! Yeah major pain tutorial lol I just wanted to train myself. There are much easier ways
thanks oceano good explanation, the only thing i cannot understand is why in the while condition of the void create_list function. the subfunction found_newline finds 1 means there is '
', so by logic it should stop the condition and not copy the last list which contains the '
', but in your explanation it copy everything, where i misunderstood?
19:37 I mean why you read first and after check while condition?
Hi, Oceano
first thanks, for this crazy tutorial hahahah😅
so what should I return in this project:
the line before we reach the null terminator '\0' and include the null terminator
or return the line(lines) after the '\0' until the EOF
thank you for this video great help
Ty very much!
good job man
is there a reason why the "Append" function is not in the header file ?
Can you explain where the str_buf comes from the the append function? It’s not declared anywhere.
its declared in the header file
Thanks
👀👀♥️♥️ Ty u crazy!
Hey ! Thanks a lot for your vidéo, it helps a lot to understand more !
For dealloc function, why did you free buf only if clean node is NULL ? And not in any case ? And why do you bring it to dealloc and don't free it directly in polish ?
Hello Cecile! I try to remember what i wrote 🤣
Here i say: “if str_buf contains at least 1 char, make this node the new head for next call to gnl”
else
“clean the buffer and the node”
if (clean_node->str_buf[0])
*list = clean_node;
else
{
free(buf);
free(clean_node);
}
So if the buffer is empty, i don’t need it. Of course this is bad design code (i already feel cringe for old code 🤣), i could have used only clean_node struct that already contains the buffer, if i correctly recall my code.
So i don’t free in every case simply because if there is a string inside buf, i’ll need the at the next gnl call.
Polish is a special function to clean the linked list last node up to
, so i decided to keep the clean up deallocs in another function.
I hope i responded u!
@@onaecO Thank you so much for you answer !
I think now it's more clear for me :
- buf and clean_node->str are pointing the same adress so if you clean buf you clean somehow clean_node->str too ?
And don't be ashamed of your code : for beginners like me it's dynamite seriously ! 😂👌
Thx for the video=) Despite on I've made a project, there was a bunch of interesting information.
One question: which IDE do you use. And could you pls share some basic settings of your .vimrc file? I see that you have autocomplete option in it. And, honestly, I don't know how to switch it on.
Many thx in advance.
Bro, Thx for the comment!
As you know these files are super tedious to decipher..i should properly make a video about.
Anyway most ideas you can get from here
~th-cam.com/video/gnupOrSEikQ/w-d-xo.html
this is the actual file, feed this to GPT + video and i think wont be super hard
vimrc
syntax on
set number
set tabstop=4
set shiftwidth=0
set backspace=indent,eol,start
filetype plugin on
call plug#begin('~/.vim/plugged')
Plug 'davidhalter/jedi-vim'
Plug 'sheerun/vim-polyglot'
Plug 'nvie/vim-flake8'
Plug 'tpope/vim-commentary'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug '42Paris/42header'
Plug 'octol/vim-cpp-enhanced-highlight'
"Plug 'ycm-core/YouCompleteMe', {'do': 'python3 install.py --clangd-completer'}
"Plug 'valloric/youcompleteme'
Plug 'vim-syntastic/syntastic'
Plug 'preservim/nerdtree'
Plug 'pboettch/vim-cmake'
Plug 'ryanoasis/vim-devicons'
Plug 'tiagofumo/vim-devicons-colorschemes'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
" Python development plugins
call plug#end()
let g:jedi#force_py_version = 3
let g:jedi#auto_complete = 1
let g:jedi#show_docstring = 1
let g:jedi#show_call_signatures = 1
let g:jedi#auto_completion_start_timeout = 0
let g:jedi#auto_complete_delay = 0
let g:jedi#auto_complete_trigger_length = 1
" Set the Airline theme
let g:airline_theme='onedark'
"Automatic nerdtree
map :NERDTreeToggle
"
"colors devicons
"colorscheme murphy
"DEBUG HIGHLIGHT
highlight DEBUG ctermfg=black ctermbg=yellow guifg=black guibg=yellow
"vim no split
nnoremap :edit
"COC stuff
" Use the clangd language server for C and C++
let g:coc_global_extensions = ['coc-clangd']
" Enable completion for C and C++
"autocmd FileType c,cpp inoremap
" \ pumvisible() ? "\" :
" \ check_back_space() ? "\" :
" \ coc#refresh()
"function! s:check_back_space()
" let col = col('.') - 1
" return !col || getline('.')[col - 1] =~ '\s'
"endfunction
" Enable diagnostics (errors and warnings)
let g:coc_global_extensions = ['coc-clangd', 'coc-diagnostic']
" Show diagnostics in the sign column
autocmd CursorHold * silent call CocActionAsync('diagnosticRefresh')
autocmd CursorHoldI * silent call CocActionAsync('diagnosticRefresh')
"Enter to select suggestion
inoremap pumvisible() ? "\" : "\"
" Use a lighter sign column
highlight SignColumn ctermbg=NONE
highlight SignColumn guibg=NONE
" Configure coc-clangd
let g:coc_clangd_binary = 'clangd' " Path to clangd binary
let g:coc_clangd_args = ['-header-insertion=never'] " Arguments for clangd
" Define the color for C warnings
highlight cWarn ctermfg=red guifg=red
" Set the syntax highlighting for C warnings
autocmd Syntax c syn keyword cWarn contained warning
" Set the color of diagnostic error messages
highlight CocErrorSign ctermfg=white ctermbg=red guifg=#ffffff guibg=#ff0000
@@onaecO By the way... I don't know if you like it, but I was a bit disgusted about warning style icon in Coc (that ridiculous triangle with exlamation mark inside). So I've changed the rule a little bit=)))
" Set warning color and sign
highlight CocWarningSign guifg=red ctermfg=red
let g:coc_user_config = {
\ 'diagnostic': {
\ 'warningSign': '!!'
\ }
\}
Now it looks much prettier=)
There is a reason you chosed to implement the project with linked list? It should be less efficient from what i know.
Hey, not really. Just to train myself on linked lists. This is arguably a bad implementation indeed 😁
Cool
is there reasaon why we need to define BUFFER_SIZE 10 instead of just writing 10? or is it just convenient?
The thing is that BUFFER_SIZE is a macro defined at compile time, it can be 1 , 42, 1 million, whatever. If you check my code i have in the .h file
github.com/suspectedoceano/get_next_line/tree/main
you find this
# ifndef BUFFER_SIZE
# define BUFFER_SIZE 10
# endif
Just in case the value is not provided during compilation.
Hardcoding 10 misses the point of the exercise, i.e. handling whatever buffer size. I hope i answered u ;)
@@onaecO ohhhhh so the reason why we marcro defined is because we can change all of it instantly without having to keep chaning all the variable one by one.
@@thebestteacher7466 Bingo! that’s exactly why they are useful.
This “refactor the code” instantly.
The more variables & constants , the better the code. Hard type values is bad, search for “magic numbers code”.
Good work!
I am a huge fan, and I always follow you.. But I am really sorry to tell you that this video made the task even harder for a beginner. the fact you are using linked lists approach while beginners just got introduced to the linked lists in the bonus part of libft and they havent even properly used it and got handy with it, would definitely make me not suggest this video for a beginner. Sorry, and keep it up. cheers!
Yeah you right! Indeed I just wanted to train myself here, there are much simpler implementations. Ty for feedback ✌️
@1337-rw6xh @amireid8496 How would you approach this project, then? I'm about to start it, and I'm feeling a bit lost. Thank you!
come in discord discord.gg/js2mw7wBk4
Never seen such a complicated explaination on this topic try to switch not to much and keep your focus on the subject. I have seen this video and compared to other things on the internet this seem like higher math.
Thx for the comment
I tried my best, i know it's not easy
th-cam.com/video/-Mt2FdJjVno/w-d-xo.html great video on this topic checkout his explanation he really keeps it onsubject and leaves out the unnecessary stuff
if you read the description , i had already mentioned the video. I just wanted to add smtg to that explanation , failing as i see
Thx again for feedback
Actually, I found your explanation and code quite understandable and useful. I decided to stick to your approach to this problem. Thank you sirrr :)@@onaecO
to be honest man, you good but the way you code is straight ahh, you make your code so complicated when it do basic stuff.
Agree! Indeed this is me trying to “fuck around to get it done” back when I was a student, If I look back to my code I 🙈🙈🙈.
Frankly I never expected many views, this channel was me just training on explaining things