How to use scanf with fgets

  Рет қаралды 33,199

CodeVault

CodeVault

Күн бұрын

Пікірлер: 89
@ziadhamdi9526
@ziadhamdi9526 Жыл бұрын
I was so confused whule working on a practice problem, and you sir, helped me, not only figure out the solution, but also understand why it is the solution. Thank you bro!
@b.t5512
@b.t5512 2 жыл бұрын
Nobody talked about that problem, only you did that and helped me. Thanks a lot man!
@MKSundaram
@MKSundaram 3 жыл бұрын
Wow! That's why follow your channel, here I get not only solutions but also the underhood mechanism behind the behavior. Keep up the good work. Thanks for providing such wonderful lectures.
@PETERTRITSCH
@PETERTRITSCH 2 жыл бұрын
Your C language tutorial is a very high-quality course. Very effective! Thank's.
@23t1dsd86v2
@23t1dsd86v2 3 жыл бұрын
Thank you so much for your C tutorials. Pls keep 'em coming!!
@stonedcodingtom9097
@stonedcodingtom9097 2 жыл бұрын
You are explaining C language the best on YT. Thx!
@jonathanlin-rv2zl
@jonathanlin-rv2zl Жыл бұрын
Thank you so much, I was so confused on why my fgets function was not executing, but worked completely fine when I moved it at the very start of my main function. Now I know😂
@gammyhorse
@gammyhorse 2 жыл бұрын
It's really sad that C is such an old language and yet still they didn't solved this problem. Thanks for another well explained video.
@CodeVault
@CodeVault 2 жыл бұрын
Old languages come with a lot of problems behind the scene. Especially when it comes to common functions such as scanf. If you "fix" this issue in a new version of C, who knows how many other pieces of old code rely on this exact functionality that we think is broken. C and C++ for that matter have always been backwards compatible and these are the kind of issues that remain due to that. It's a similar issue (but much larger) with x86 assembly
@gammyhorse
@gammyhorse 2 жыл бұрын
@@CodeVault About old languages my favorite is Pascal. I really love programming my personal projects particularly in Free Pascal using Lazarus IDE. To be fair though, Free Pascal is not really an old language, it's surprisingly modern and powerful. But I cannot say that I dislike C because of the above problems mentioned. I like C very much.. it gives me the feeling that I understand what I'm doing. And of course your videos are very helpful, actually they are the best in YT. No exaggeration on this.
@fulcrodestructor8518
@fulcrodestructor8518 2 жыл бұрын
thank you very much, I looked for over 20 minutes for a solution to my problem and there was not a single video or webpage that explained the issue, thanks for the 10/10 tutorial
@mohammedfaizy1110
@mohammedfaizy1110 Жыл бұрын
Thank you so much! I was so frustrated on why my code is not working and searched on the web but found nothing. And then I found this video and the way you explained it was so amazing and easy to understand and my code is working! Thank you!
@mehedihasanmridul5661
@mehedihasanmridul5661 3 жыл бұрын
You are a life saver. Can't thank you enough !!!!
@ISKLEMMI
@ISKLEMMI 2 жыл бұрын
This was a great explanation, as all your videos are. Thank you!
@moosaawad1627
@moosaawad1627 Жыл бұрын
Thanks a lot, that was a clear and concise explanation :)
@jelsonrodrigues
@jelsonrodrigues 2 жыл бұрын
Is possible to use "%d%*c" on scanf format specifier. That will read the number (%d part) and the " ", then will ignore the " " (the * character ignores the matching case and the "c" means a character), this way you dont have to make another function call (fgetc(stdin)) and also use one less line.
@CodeVault
@CodeVault 2 жыл бұрын
Yea, sure... That's a nice way of getting around this issue with scanf!
@hexcodeff6624
@hexcodeff6624 2 ай бұрын
That doesn't work with string inputs though, only integers
@firepower01
@firepower01 2 жыл бұрын
You are amazing. I have to learn C for an intro to computer systems class and your tutorials have been invaluable for my learning. Thank you!
@aseeldee.1965
@aseeldee.1965 3 жыл бұрын
thank you very much your videos are like a savior to me keep going, man!
@xsangrezulx
@xsangrezulx 2 жыл бұрын
You helped me, so let me help you with that KZbin algorithm.
@Luigi-qt5dq
@Luigi-qt5dq 3 жыл бұрын
Thanks a lot, I was going crazy
@thiagoflores9029
@thiagoflores9029 Жыл бұрын
Man, you are awsome. Thank you for what you do
@towtruckn
@towtruckn Жыл бұрын
Thanks for the great video. It seems all the input functions ie. getchar(), scanf() getc() etc... use the same input buffer and is why the problem occurs ie. when characters remain in the buffer they are recognized as user input by the next call to scanf() and is the reason they are skipped. In the video was used fgetc() to clear the newline; however, trying getchar() it seems to do the same job.
@CodeVault
@CodeVault Жыл бұрын
Yeah, there are many similar functions to fgetc(). There are so many that there's actually a video regarding this: code-vault.net/lesson/t1rx0xlx2e:1603733525238
@abirahammedbhuiyan2781
@abirahammedbhuiyan2781 3 жыл бұрын
Mashallah. Your videos are awesome. Keep up the good work brother.
@Klusio19
@Klusio19 2 жыл бұрын
Thank you very much, I was so confused why it does work like that, but you explained everything perfectly
@somebaconguy6593
@somebaconguy6593 3 жыл бұрын
Thanks so much for this video, it helped me a lot with my C programming assignment!
@uatilla13
@uatilla13 Жыл бұрын
Thank you! Excellent content!
@gameplayvideos9758
@gameplayvideos9758 3 жыл бұрын
Thank you very much for the simple solution and explanations !
@takemebackto2077
@takemebackto2077 8 ай бұрын
really useful to me, thank you for your video❤
@tmthy.mp4
@tmthy.mp4 3 жыл бұрын
exactly what I needed, Thank you so much!
@073_tia_bayualikhlasswari9
@073_tia_bayualikhlasswari9 2 жыл бұрын
thanks for tutorials thats help me
@Anonomyous-cg1ye
@Anonomyous-cg1ye Жыл бұрын
Awesome video as usual
@alv1947
@alv1947 2 жыл бұрын
really good video.you earned new subscriber.
@MiltonUwU_
@MiltonUwU_ 3 жыл бұрын
thanks, this helps me a lot :D i send you my rewards from Mexico!!!
@cleightthejw2202
@cleightthejw2202 3 жыл бұрын
You said you hope we get something out of this video. I'm telling you as matter of fact that ALL of the videos you put out are beneficial to one degree or another for anyone watching them. I personally noticed very quicly about you that you give some substance in your vieos that many really do not in the 'C' language. It is like they give the same out of the book example. And that doesn't help ppl learn when they are all using the same examples and even simple examples at that. So I definitely appreciate and thank you for not doing that but for giving better quality. I do hope that your viewership and subscriber base increases and does so quickly.
@prathameshredij1039
@prathameshredij1039 3 жыл бұрын
Absolutely true, I searched a lot but never found such good explanation in any other video.
@AlkNA
@AlkNA 3 жыл бұрын
Good explanation, thank you!
@Yasuo_13459
@Yasuo_13459 Ай бұрын
This helps a lot tysm bro
@manmanual
@manmanual 2 жыл бұрын
I love you man. Thanks
@Recapninja25
@Recapninja25 Жыл бұрын
Thanks a lot for this
@aditudor4805
@aditudor4805 2 жыл бұрын
man you re worth 2 likes from me thank u so much
@dfgw8416
@dfgw8416 3 жыл бұрын
Deep Knowledge!!! Nice
@leroydupuis9648
@leroydupuis9648 3 жыл бұрын
thank you so much.
@coltondranchuk5182
@coltondranchuk5182 3 жыл бұрын
Thank You.
@riverwest360
@riverwest360 Жыл бұрын
Thanks a lot sir
@KangJangkrik
@KangJangkrik 3 жыл бұрын
When I use debian, pointing fgets to /dev/urandom file descriptor would cause kernel panic. Seems like it fixed on newer kernel. I use arch now btw
@pa1382
@pa1382 2 жыл бұрын
thank you man.
@strahinjasamardzija2777
@strahinjasamardzija2777 3 жыл бұрын
Amazing content!
@TheLostCrusader.
@TheLostCrusader. Жыл бұрын
A life lifesaver
@davidn5013
@davidn5013 3 жыл бұрын
Nice work! Your tutorials have given me inspiration. Do you think that scanf(“%[^ ]s”, message); have a place here?
@CodeVault
@CodeVault 3 жыл бұрын
I always have issues with that scanf. But yes, you could use that "%[^ ]s" format in place of the scanf in the video and it should also work fine. Although... I really suggest you just use fgets at that point
@jesusstudentbrett
@jesusstudentbrett 2 жыл бұрын
Thanks sooo much for your awesome videos, but I keep seeing you say "You can check up on top" where you are pointing upward... but I cannot figure out what "up on top" means. There is more than one C language playlist soooo hard to figure this out. Thank you!
@CodeVault
@CodeVault 2 жыл бұрын
I mean in the top right corner there's a "i" icon that you can click to see videos I link to this video
@vivaanreddy8771
@vivaanreddy8771 2 ай бұрын
Thank you 😭
@Mohamed_Amine_Bennacef
@Mohamed_Amine_Bennacef 2 жыл бұрын
God bless you
@sultantanim6428
@sultantanim6428 3 жыл бұрын
Thanks a lot
@longangthanh7857
@longangthanh7857 2 жыл бұрын
How about using fflush(stdin); after each use scanf or fgets, v.v... . I think it's more effectively
@CodeVault
@CodeVault 2 жыл бұрын
That would also work, yes. Although it is regarded as undefined behavior: stackoverflow.com/questions/2979209/using-fflushstdin
@ecthelion1517
@ecthelion1517 Жыл бұрын
Sir, you are great. I searched for this solution for quite some time nothing worked, but fgetc(stdin) did the trick easily!
@parrotparrot1948
@parrotparrot1948 2 жыл бұрын
Hmmmm I got a question here, why don't you use rewind (stdin) :0
@CodeVault
@CodeVault 2 жыл бұрын
Because you can't seek on console streams (such as stdin) and, technically, it might result in undefined behaviour as it's not specified in standards. Although, yes, that works
@neon7874
@neon7874 2 жыл бұрын
why not use fflush(stdin); u could clear the buffer too.
@CodeVault
@CodeVault 2 жыл бұрын
fflush(stdin) is not standard, that's why it's not recommended to use it. You can read more on this by others more experienced: stackoverflow.com/questions/2979209/using-fflushstdin
@marcusmanmarcus
@marcusmanmarcus 3 жыл бұрын
Thanks a lot! How do i detect EOF?:)
@CodeVault
@CodeVault 3 жыл бұрын
The return value is dependent on whether or not you've hit EOF: www.cplusplus.com/reference/cstdio/fgets/ Or you can just check with feof
@longh
@longh 2 жыл бұрын
thanks!
@hemantsaini1713
@hemantsaini1713 3 жыл бұрын
what if i use gets() in place of fgets() ......?
@wailfulchunk7108
@wailfulchunk7108 3 жыл бұрын
can we do the same with gets?
@CodeVault
@CodeVault 3 жыл бұрын
Yes, but gets is vulnerable: code-vault.net/lesson/q2v3wz26zw:1603733525494
@masabh
@masabh 3 жыл бұрын
Wish I watched this before wasting 3 hours.
@anti2023
@anti2023 Жыл бұрын
how do you make to run the program run in terminal on vscode using debug?
@CodeVault
@CodeVault Жыл бұрын
There are a couple videos regarding vscode here: code-vault.net/lesson/4wy66ezt7u:1610303902122
@huytan7205
@huytan7205 2 жыл бұрын
can we use fgets to read stdin line by line?
@CodeVault
@CodeVault 2 жыл бұрын
Yes, and it's recommended you actually use it in place of scanf
@ade5324
@ade5324 2 жыл бұрын
ty
@gardalson3288
@gardalson3288 Жыл бұрын
Hi guys, I"m just a newbee when it comes to c howveer when i use fgets() it ommits the first character of my code and prints outn the rest can some one explain or provide resources for me to understand how this works.. Thankyou: char school[30]; printf("enter schools name"); fgets(school, 30, stdin);
@CodeVault
@CodeVault Жыл бұрын
I tested the code and it works just fine. What do you mean by "it omits the first character"? Can you give me an example and the code you used to test this?
@gardalson3288
@gardalson3288 Жыл бұрын
​@@CodeVault​sure char school[80]; printf("Enter the high school you went to: "); fgets(school, sizeof(school), stdin ); printf("the schools is %s",school) oooh sorry, i kind forgot to add the name of the variable in my printf statement
@CodeVault
@CodeVault Жыл бұрын
Yeah, seems to be working fine. You're using fgets correctly
@eukku_e
@eukku_e 2 жыл бұрын
огонь
@lunte0198
@lunte0198 2 жыл бұрын
the fuck
Arrays as function parameters in C
13:28
CodeVault
Рет қаралды 12 М.
Be Careful When Using scanf() in C
12:22
NeuralNine
Рет қаралды 129 М.
SISTER EXPOSED MY MAGIC @Whoispelagheya
00:45
MasomkaMagic
Рет қаралды 13 МЛН
Бенчик, пора купаться! 🛁 #бенчик #арти #симбочка
00:34
Симбочка Пимпочка
Рет қаралды 3,6 МЛН
Synyptas 4 | Арамызда бір сатқын бар ! | 4 Bolim
17:24
龟兔赛跑:好可爱的小乌龟#short #angel #clown
01:00
Super Beauty team
Рет қаралды 68 МЛН
Scanf Basics: the good, the bad, and why so many pointers?
15:07
Jacob Sorber
Рет қаралды 24 М.
Reading/Writing structs to files (aka Serialization)
14:41
CodeVault
Рет қаралды 76 М.
All Rust string types explained
22:13
Let's Get Rusty
Рет қаралды 178 М.
you will never ask about pointers again after watching this video
8:03
What are variadic functions (va_list) in C?
13:49
CodeVault
Рет қаралды 22 М.
Python Decorators in 15 Minutes
15:14
Kite
Рет қаралды 447 М.
Object-Oriented Programming is Embarrassing: 4 Short Examples
28:03
fgets is unsafe! So what’s the alternative?
11:32
Code With Huw
Рет қаралды 3,2 М.
SISTER EXPOSED MY MAGIC @Whoispelagheya
00:45
MasomkaMagic
Рет қаралды 13 МЛН