How to do error handling in C and get specific error in a human readable form.
Social links:
Website: cacharle.xyz
Github: github.com/cacharle
Linkedin: / charles-cabergs-328aa8214
How to do error handling in C and get specific error in a human readable form.
Social links:
Website: cacharle.xyz
Github: github.com/cacharle
Linkedin: / charles-cabergs-328aa8214
At last, finally someone makes great advanced C videos, fantastic! And big thanks for not having disturbing background music and irrelevant graphics editing. Your pedagogical skills are also great, because you have the editor and the console side by side and the pace is fine and not having irrelevant info included on the screen. What about making a video or more about sending outputs to a default printer? Of course you got a new subscriber.
Thank you for the kind words :) Having as little distractions as possible is my trade mark and it will keep being that way. Unfortunately I have never written code to interact with a printer and I don't have a printer at home so I can't help you with that (I wouldn't be surprised if you can find a clean cli tool or a library to interact with printers tho)
@@cacharle I have now discovered a library cops.h and understand, that is widely used in Linux. I can use Raylib.h and print ttf characters and lines on a virtual graphical page and then via cups make a hardcopy to the printer. And this little code can also print although I'm new to Linux and do not yet understand the command. #include #include #include int main() { char text[] = "Hello, Printer! "; char command[256]; sprintf(command, "echo \"%s\" | lp -d $(lpstat -d | cut -d' ' -f4)", text); if (system(command) == -1) { perror("Failed to print"); return 1; } printf("Text printed successfully! "); return 0; } I admit it's not my code. :o)
great video but I thought it would be c# XD
Super useful! Thank you so much! Really great stuff 🙂
I'm glad you're enjoying this series :D
A good next video on Advanced C might be how to take user input from a user safely in a loop in a "clean" way. It's harder then it might sound.
Indeed, I could make a video on `getline`, a very useful function. Or one where I detail the *get* functions and warn about buffer overflows with `gets`. Thank you for your suggestion.
@@cacharle 👍
Great video man keep up the good work 😊
Thank you :D
Great video as always
Thanks! :D
fine video but man the gruvbox colorscheme is so timeless. looking forward to your work!
Thanks, I like the comfy vibe of the gruvbox theme, makes me feel at home 😅
Nice!
Great series, thank you! I am a software engineer for about two decades, but always used managed languages like C#, Java etc. Now i have to learn c and delve deeper into low level programming. I know the basics but i am so used to having dynamic arrays, lists, maps, even a proper string data type and all that stuff. Sometimes i have a hard time with this. When i look on YT about C tutorials, they all start at zero for total beginners. What i need is a complete tutorial for programmers switching to C. What are the best practices when you need dynamic arrays or lists or maps. Will one write them themselves? If yes, could you show it to us? What are the best practices about memory management? What allocators are suited best for what needs, how do they work, and how do you implement them? Could you make such series? That would be really awesome!
Hi, I just made a video about writing your own dynamic array in C (and I also played around making it a "generic" data structure on stream). I am planning on doing more videos like this in the future. I think the main advice I have for someone that comes from a higher level programming language is try to just use the basic C features *as much as possible*. You will be very surprised by how many times it is possible to replace a dynamic array by a fixed size array, a map with an enum and a "lookup table", a string by a char array. Do not try to shoehorn these high level constructs in C. If you really need them, you can either rewrite them yourself or there is probably libraries that do that for you aswell (altho I've never felt the need to use one)
I'm a hobby programmer and I am at the finale of an little application for my wife's business, a relations database in C, Raylib graphics for user interface and Linux Mint. I'm using CodeBlocks and the debugger is very good to tell you where your logic fails. Because I really want learn C, I decided to build my my own string handling for editing. It's a enormous satisfaction, when your own library does the handling correct and gives lots cries, when it's not.
@@grimvian I also started writing C using CodeBlocks :D it is pretty good to learn but it started to get in my way when I wanted to do more advanced stuff from what I remember (ofc don't change editors if you're comfortable with it) The C standard library already has a lot of string handling functions which are very useful. Depending on your usecase, it might be necessary to implement a more dynamic string data structure like C++ or Python (which is basically just a dynamic array of characters). If I was you, I would really try to keep it simple at first and only use the standard library and regular character arrays.
@@cacharleI' very bad at typing and reading, so I'll have to stick with CodeBlocks and I'm a hobby coder most of the time. I do not think for a second I'll do better string handling than the standard library, it's just because my own library keeps me on my toes. I also used it for the editing in my database for my wife's business, although it was quite a task have the data on the disk and string handling and the graphics in place, but it seems to work fine now or else I'll know very quickly, because of my wife :o). Even insert and overwrite and a timed cursor, that correspond to ins/overwrite are in place. So it's great that someone like you is making advanced C videos and I think many C learners have tried many of the beginner videos and want to go on. I saw that a advanced C course costed about 3000 euros in Denmark, where I live...
Would love a video on varargs!
Already made one: kzhead.info/sun/iJyso7mopKSNrYE/bejne.html And for macro variable argument aswell: kzhead.info/sun/gseHfJRviIOFiYE/bejne.html
@@cacharle Amazing brother 🙌
very good.... maybe also show the "goto" pattern for free'ing resourcs in case of error.
Ye, I was planning on doing that but I've never used it myself, I just know it exists and how it works.. so I feel less qualified to talk about it
Well thx whole resource free'inf in the context of errors is quite tricky to get tight IMO. Multiple techniques exist just show the one you use?
I use the dumb and easy way: r1 = f1(); if (r1 == NULL) return NULL; r2 = f2(); if (r2 == NULL) { free(r1); return NULL; } r3 = f3(); if (r3 == NULL) { free(r1); free(r2); return NULL; } I can see why someone would want to remove the duplicate free's, but tbh, I very rarely encounter a case where I have more than 2/3 resources in one function so this simple technique is fine for my needs.
Yeah that's fair. I think it's still worth a video to explain that.
Indeed, I'll think about it.. Any other resource management technique I should know about other than the dumb one and the goto one? I think I saw some people make a `defer` macro but I'm not sure if it was in C++ or C.. EDIT: it was in C++ www.gingerbill.org/article/2015/08/19/defer-in-cpp/ :'(
Super vidéo mais ça aurait été bien de mentionner goto 👍
Je sais, quelqu'un me l'a dit dans un autre commentaire mais je n'utilise pas cette methode personnelement
En français, S.V.P. 😂
jamais! 😄
Hum… réécrire des fonctions, un accent français… 42?
Oui, j'ai fait l'ecole 19 a Bruxelles 😅
@@cacharle haha démasqué! 😜 C’était bien à Bruxelles ? C’est recommandable ?
@@basilenordmann7356 Oui c'etait tres bien. Apres je suis jamais aller visiter d'autre ecole dans le Network 42 donc je peux pas vraiment comparer