Let's build a mini printf function

  Рет қаралды 23,251

Oceano

Oceano

Күн бұрын

🇮🇹🍕🍝Canale Italiano - / @onaeco_ita
. Full printf with format handling
- • Let's build a printf! ...
- • Let's build a printf! ...
Useful sources
suspectedoceano.notion.site/p...
typedef struct 🔗s_links🔗
{
👨🏻‍🏫 Udemy course for total beginners, pre_knowledge before C (Overflow, 2’s complement, BASH, VIM…) - www.udemy.com/course/oceano_0...
📑 Notion community page (FREE coding sources) - suspectedoceano.notion.site/O...
🧾 Medium (code articles) - / jalal92
📲 Telegram group - t.me/suspectedoceanO
💻 GitHub - github.com/suspectedoceano
🛸 Discord - / discord
🐦 Twitter - / suspectedoceano
☕️ ChannelSupport - www.buymeacoffee.com/suspecte... (if you read this, you are already supporting, TY!)
} 🔗t_links🔗

Пікірлер: 54
@minimalSwift
@minimalSwift 4 ай бұрын
my friend, I love your videos! But this miniprintf has a problem. I also put it here so that other can see it. I mean I don't pretend to let you do all the work and criticize. :) It is a small thing, but you pass (va_list) )ap to the next function by value and this causes indefinite behavior: (Quote as per C99) >The type declared is va_list which is an object type suitable for holding information needed by the macros va_start, va_arg, va_end, and va_copy. If access to the varying arguments is desired, the called function shall declare an object (generally referred to as ap in this subclause) having type va_list. The object ap may be passed as an argument to another function; if that function invokes the va_arg macro with parameter ap, the value of ap in the calling function is indeterminate and shall be passed to the va_end macro prior to any further reference to ap So. It might happen to work on one architecture, but not another, due to differences in how va_list is implemented between architectures. (it did not work on my Mac M1 for instance, I was getting rubbish printed out! Then I double checked the code). > It is permitted to create a pointer to a va_list and pass that pointer to another function, in which case the original function may make further use of the original list after the other function returns. Solution is easy. Use a va_list pointer. int print_format(char specifier, va_list *ap) Thank you for the video. I loved the recursive implementation of the digits... :)
@onaecO
@onaecO 4 ай бұрын
Ty very much for the kind words, and for adding value for other. I'll pin this! ( I just didn't know lol )
@minimalSwift
@minimalSwift 4 ай бұрын
Thank you for your work ! :) @@onaecO
@FilipBalakovski
@FilipBalakovski Ай бұрын
I have the same problem with printing garbage values on my architecture (MINGW64). Online debugger (GDB) works just fine. Your fix just gives me a warning and the problem persits :/ Any other suggestions?
@noskov5
@noskov5 8 ай бұрын
mate I love your videos. Keep it going
@onaecO
@onaecO 8 ай бұрын
Ty very much bro 👊🏻
@renans.5135
@renans.5135 8 ай бұрын
Awesome video! Kudos from 42 Rio de Janeiro; you've been a great help since my piscine and you continue to be a a spectacular source of help, man. Keep up the good work!
@Yasspums
@Yasspums 6 ай бұрын
does your printf got valid ? im gonna do like him probably
@renans.5135
@renans.5135 6 ай бұрын
It sure did! You can base your work off of him for sure :)
@user-jk2pu7tj6w
@user-jk2pu7tj6w Ай бұрын
Hi from 42 Paris !!
@vitalis3285
@vitalis3285 15 сағат бұрын
I am glad to be your friend, my friend! And thx, for the video, my friend!
@onaecO
@onaecO 14 сағат бұрын
Yeah, rately I happen to say "my friend" lol
@CodingHk
@CodingHk 10 ай бұрын
Thanks for this awesome video, C seems to hard to understand and I give it enough time yet still complicated (10hrs+ daily) but this video has helped clear and bring back the hope that I can still learn it. Thank you again
@onaecO
@onaecO 10 ай бұрын
10h daily it s massive, congrats!! Agree on everything, C is very very hard. We have to really have patience and study 😁
@adampassaretti9149
@adampassaretti9149 6 ай бұрын
Bro i really need a bit of your work ethics, i'm slacking off too much
@CodingHk
@CodingHk 6 ай бұрын
@@onaecO Yea 10hrs a day, a strict coding bootcamp 😀
@CodingHk
@CodingHk 6 ай бұрын
@@adampassaretti9149 you mean me or onaecO?
@vikassharma-lp9bp
@vikassharma-lp9bp 9 ай бұрын
best tutorial on printf, please make video on complete printf :)
@onaecO
@onaecO 9 ай бұрын
Ty very much 👊🏻
@giovannitroiano
@giovannitroiano 11 ай бұрын
Thanks
@onaecO
@onaecO 11 ай бұрын
👀♥️♥️
@ynelniino
@ynelniino Жыл бұрын
thank you 🙏🙏
@onaecO
@onaecO Жыл бұрын
Thank you for the comment 🔥
@pedroalmeida8453
@pedroalmeida8453 8 ай бұрын
42 school, anyone?
@alanishadama
@alanishadama 8 ай бұрын
sim
@Ylizz96
@Ylizz96 8 ай бұрын
Ayoo!
@anonym_3241
@anonym_3241 7 ай бұрын
Qwasar?
@ninjingninja
@ninjingninja 3 ай бұрын
I guess it's everyone... Why else?
@user-jk2pu7tj6w
@user-jk2pu7tj6w Ай бұрын
Hi !
@erikseferi2241
@erikseferi2241 Жыл бұрын
Hello, thanks from 42 Wolfsburg for the video and I also took some inspiration from your Github and made the printf work with bonuses. Do you have slack or discord to reach you out ?
@onaecO
@onaecO Жыл бұрын
Dear friend, u are crazy! printf bonus was a major pain 😂 You should do a tutorial, there is not in yt 🔥 You got me the idea and i just created a telegram group ~t.me/suspectedoceanO We can create a 42 gang ;)
@giovannivolante7302
@giovannivolante7302 5 ай бұрын
Great work, thanks! A side question: are you using vim? In these case, how do you obtain suggestions and autocompletion?
@onaecO
@onaecO 5 ай бұрын
" Basic Vim settings set number set tabstop=4 set shiftwidth=4 set backspace=indent,eol,start filetype plugin on call plug#begin('~/.vim/plugged') " Essential plugins Plug 'neoclide/coc.nvim', {'branch': 'release'} Plug 'dense-analysis/ale' Plug 'preservim/nerdtree' Plug 'vim-airline/vim-airline' Plug 'vim-airline/vim-airline-themes' Plug 'octol/vim-cpp-enhanced-highlight' "Plug 'ryanoasis/vim-devicons' call plug#end() " Set the Airline theme let g:airline_theme='onedark' " Automatic nerdtree toggle map :NERDTreeToggle " COC configuration for real-time diagnostics with clangd let g:coc_global_extensions = ['coc-clangd'] " Enable diagnostics (errors and warnings) and update them on cursor hold autocmd CursorHold,CursorHoldI * silent call CocActionAsync('diagnosticRefresh') " Enter to select suggestion from completion menu inoremap pumvisible() ? "\" : "\" " Configuration for coc-clangd let g:coc_clangd_binary = 'clangd' let g:coc_clangd_args = ['-header-insertion=never'] " Set the color of diagnostic error messages highlight CocErrorSign ctermfg=white ctermbg=red guifg=#ffffff guibg=#ff0000 " Highlight DEBUG statements highlight DEBUG ctermfg=black ctermbg=yellow guifg=black guibg=yellow " Param suggestion highlight CocInlayHint guifg=yellow guibg=NONE ctermfg=yellow ctermbg=NONE highlight link CocInlayHintParameter CocInlayHint highlight link CocInlayHintType CocInlayHint highlight CocInlayHint guifg=yellow guibg=NONE ctermfg=white ctermbg=NONE gui=bold cterm=bold highlight link CocInlayHintParameter CocInlayHint highlight link CocInlayHintType CocInlayHint " Configure ALE let g:ale_sign_error = '✘' let g:ale_sign_warning = '⚠' " Define custom colors for warning text highlight link ALEWarningMsg WarningMsg "highlight ALEWarning ctermfg=red ctermbg=NONE "AUTOSAVE "autocmd TextChanged,TextChangedI * silent write autocmd TextChanged,TextChangedI * \ if &buftype ==# '' || &buftype == 'acwrite' | \ silent write | \ endif " Enable Coc let g:coc_global_extensions = [ \ 'coc-clangd' \ ] " Use Coc for diagnostics (errors and warnings) autocmd CursorHold,CursorHoldI * silent call CocActionAsync('diagnosticRefresh') " Enable inline error and warning display let g:coc_sign_error = '✘' let g:coc_sign_warning = '⚠' let g:coc_status_float_enable = 1 " Enable floating status information let g:coc_status_colors = { \ "Warning": "white", \ } " Set the colorscheme for floating windows au ColorScheme * hi CocFloating ctermfg=white guifg=white ctermbg=black guibg=black
@giovannivolante7302
@giovannivolante7302 5 ай бұрын
@@onaecO Many many thanks
@marceaukersuzan9938
@marceaukersuzan9938 9 ай бұрын
soo litt man this video is fucking fire man !!!!!!
@onaecO
@onaecO 9 ай бұрын
HAHA ty!
@oneloveafrica8860
@oneloveafrica8860 5 ай бұрын
tanks
@kellvynrocha3583
@kellvynrocha3583 Жыл бұрын
I L O V E Y O U
@onaecO
@onaecO Жыл бұрын
😂😂😂
@oscarms6067
@oscarms6067 9 ай бұрын
what if print_str receves NULL?
@onaecO
@onaecO 8 ай бұрын
You mean smtg like my_printf(NULL);? Well this is a seg fault, indeed it's good practice always to check for NULL when dealing with pointers, in my simple implementation I just assumed no corner cases, like passing a NULL to a printf ^^ Anyway good question 👊🏻🔥
@oscarms6067
@oscarms6067 8 ай бұрын
Also if you pass a NULL as one of the variadic arguments to be processed as a string with print_string(). This function doesn't check it the pointer is NULL, before de dereferencing . Usually, in this case the constant string "(NULL)" is printed instead.
@onaecO
@onaecO 8 ай бұрын
@@oscarms6067Yep! 100%, this is my mistake not properly handling NULLs and other corner cases, not pointing this out. I just wanted to show a boilerplate for a fully printf. I'll pin your comment for other ^^, ty for feedback!
@zoenagy9458
@zoenagy9458 6 ай бұрын
i++ is more readable when it stands alone
@user-zk9qx4rc1f
@user-zk9qx4rc1f 8 ай бұрын
As long as it norminettes
@onaecO
@onaecO 8 ай бұрын
My friend, this is clearly not the real thing. is just a sample code
@user-zk9qx4rc1f
@user-zk9qx4rc1f 8 ай бұрын
Haha just messing with you absolutely amazing video. Your understanding is immaculate. Looking forward to watch the full printf if you drop the video. Not sure if you did already. Keep up the good work mate@@onaecO
@swedishpsychopath8795
@swedishpsychopath8795 6 ай бұрын
I'm sorry - but your printf function won't work.
@onaecO
@onaecO 6 ай бұрын
I agree
@swedishpsychopath8795
@swedishpsychopath8795 6 ай бұрын
@@onaecO I'm just trolling. I'm sure it will work just fine! But you didn't get mad and didn't start to scream so I must find someone else to troll :)
@onaecO
@onaecO 6 ай бұрын
The "I don't give a f***k mode" must be always on when on internet 😂 Btw Happy new year my dear troll ♥️
@user-kh3qb1nf8x
@user-kh3qb1nf8x 7 ай бұрын
If you can't even using C write printf, it means you are a loser in programing language.
@taleuback6799
@taleuback6799 4 ай бұрын
coucou ferme ta veste bisous
@PauloConstantino167
@PauloConstantino167 7 ай бұрын
hi there, my dream is to become a printf function
Let's build a printf! Episode n° 1 : Format parser
1:09:04
Oceano
Рет қаралды 3,9 М.
Red❤️+Green💚=
00:38
ISSEI / いっせい
Рет қаралды 77 МЛН
Little girl's dream of a giant teddy bear is about to come true #shorts
00:32
Master Pointers in C:  10X Your C Coding!
14:12
Dave's Garage
Рет қаралды 289 М.
understanding ft_printf
11:23
nikito
Рет қаралды 11 М.
What are variadic functions (va_list) in C?
13:49
CodeVault
Рет қаралды 20 М.
The Story of Next.js
12:13
uidotdev
Рет қаралды 556 М.
All Rust string types explained
22:13
Let's Get Rusty
Рет қаралды 155 М.
C++ vs Rust: which is faster?
21:15
fasterthanlime
Рет қаралды 383 М.
Red❤️+Green💚=
00:38
ISSEI / いっせい
Рет қаралды 77 МЛН