Advanced Integer Input Validation | C Programming Example

  Рет қаралды 13,019

Portfolio Courses

Portfolio Courses

Күн бұрын

Пікірлер: 36
@hangminh1564
@hangminh1564 2 жыл бұрын
Still can't believe my prof and TAs expect me to do this after two lectures of C programming beginner 💀
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
Wow, that sounds tough! Good luck, I hope this video helped a little bit. 🙂
@naboulsikhalid7763
@naboulsikhalid7763 Жыл бұрын
what's beautiful in you explanation, you we through each line and what it does int term of reading int string, detecting space, then '-' sign then integers. and it looks so easy and understandable. it's also like a kind of algorithm unfolding by steps. Thank you for all what you've done and make it easier for US.
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You're welcome Naboulsi, I'm glad you enjoyed the explanation and thank you for the positive feedback! :-)
@DaiMoscv
@DaiMoscv 2 жыл бұрын
Thanks a lot, I've seen your others videos too and they were all very useful!
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
You’re welcome Bilguun! :-) And that’s excellent to hear you are finding the videos useful, thank you for sharing that feedback.
@fabianselamai6493
@fabianselamai6493 2 жыл бұрын
i only wanted to prevents characters 2:39 but when i tried this in a online compiler it wanted me to input the value 2 times, why?
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
That's a good question, but I'm not sure Fabian. :-) Sometimes with scanf() it can leave a newline character on the buffer, and when it does we can get weird behaviours where a call to scanf() almost appears to be "skipped". I wonder if something like that is happening here, but I'm not sure.
@fabianselamai6493
@fabianselamai6493 2 жыл бұрын
@@PortfolioCourses ok ty !
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
You’re welcome! :-)
@mirengeinnocent6865
@mirengeinnocent6865 Жыл бұрын
how can you use this function and read zeros as single integers? If the user enters 09, then read it as 09 not just 9. or if the user enters 0030, the function reads it as 0030 not just 30.
@rubr0nyx
@rubr0nyx Жыл бұрын
Thank you very much! Your lessons are very useful and you have a good presentation of information. Nice to learn from your videos :)
@PortfolioCourses
@PortfolioCourses Жыл бұрын
You’re very welcome, I’m glad that you’re enjoying the videos and the presentation! :-)
@kwesiafari605
@kwesiafari605 2 жыл бұрын
Mind blowing
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
I’m glad you like it! :-)
@theanguyen1015
@theanguyen1015 2 жыл бұрын
Appreciate your video. Thanks to you that I'm able to code without breaking down
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
You’re welcome Thea! I’m very glad to hear the videos are helping you to code. :-)
@bofa-zi4fj
@bofa-zi4fj 2 жыл бұрын
This is a great video. The program works great however, it doesn’t check for the cases when a user enters an int bigger than INT_MAX or smaller than INT_MIN
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
That's true! :-) Assuming we want to convert the string representation of the integer to an integer type like int, long, etc, we could then apply another "range validation" function to ensure the integer falls within the range of that type. Maybe one day I can do a video on that and post it here as an "extension" or additional validation option, that might be fun. :-)
@robintau159
@robintau159 2 жыл бұрын
Wondering how it would work for checking integers in a matrix...
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
I'm not sure Robin. :-) It works with strings, so I guess by matrix you mean a 2D array of strings? We could apply it to each string in a 'matrix of strings' I'm sure, we would need to call the function for each string.
@AI-NotesExperience
@AI-NotesExperience 2 жыл бұрын
Excellent tutorial... I hope you have the time to code the validation of float numbers.
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
Hopefully one day I can do this too. 🙂 I would use the regex library normally for handling that type of problem but I think people would be curious to see it done without using that library.
@shuu8281
@shuu8281 2 жыл бұрын
Would I be able to extract a month and date integer value if the user input is YYYY MM DD?
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
Great question! 🙂 For something like that, if you're sure the user input is going to be OK/valid, you could use something like: scanf("%d %d %d', &n1, &n2, &n3); If you're not sure the input is OK and you need to do some validation, something like strtok() might help you out to try to identify each individual integer: kzbin.info/www/bejne/pKOykKOOfL-Wabs.
@shuu8281
@shuu8281 2 жыл бұрын
@@PortfolioCourses Thank you so much! What a fast reply too lol. I'll be sure to follow your advice, great videos btw.
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
@@shuu8281 You're welcome. 🙂 And I'm glad to hear you enjoy the videos too!
@BrianParsons-or1lv
@BrianParsons-or1lv 5 ай бұрын
Good stuff 👏
@PortfolioCourses
@PortfolioCourses 5 ай бұрын
Thanks, I’m glad you liked it! :-)
@константинконстантинов-ш1п
@константинконстантинов-ш1п 2 жыл бұрын
How to do it without all of these libraries?
@PortfolioCourses
@PortfolioCourses 2 жыл бұрын
That's a great question... the solution would look very similar, but we would effectively need to create these library functions ourselves. Maybe one day I can make videos covering how to make these library functions, I have done some functions but not all the functions in this video. 🙂
@ZedP
@ZedP 2 жыл бұрын
I myself get the integer as a char[ ], and then with atoi( ) am typecasting it into a real, calculable integer. I use some ctype functions that prevent user from entering letters, special chars, spaces. For a float number I only exclude comma - and the show goes on. It is not bullet proof, I am not sure whether any validation program in C can be bullet proof (perhaps I'm wrong here). I simply hope that user won't enter something like 1;47. But your code is really great, much more sophisticated than mine.
@PortfolioCourses
@PortfolioCourses Жыл бұрын
Thanks for sharing this Zed! :-) This video is more "for fun and learning", I would suggest using regex for doing serious validation that an input matches an expected pattern of some kind: www.gnu.org/software/libc/manual/html_node/Regular-Expressions.html.
@MrPasa
@MrPasa 7 ай бұрын
I have wrote this code. It is much more easier and does the same job. #include int main() { float x; char c; while(1) { printf("Enter a positive integer: "); if (scanf("%f", &x) == 1) { if (x > 0 && x - (int)x == 0) { break; } else { printf("Please enter a positive integer. "); } } else { printf("Invalid input. Please enter a positive integer. "); while ((c = getchar()) != ' ' && c != EOF) {} } } int valid_input = (int)x; printf("Your input is: %d ", valid_input); return 0; }
Read And Write An Array Of Structs To A Binary File | C Programming Example
18:27
Be Careful When Using scanf() in C
12:22
NeuralNine
Рет қаралды 131 М.
Sigma girl VS Sigma Error girl 2  #shorts #sigma
0:27
Jin and Hattie
Рет қаралды 124 МЛН
Почему Катар богатый? #shorts
0:45
Послезавтра
Рет қаралды 2 МЛН
Counter-Strike 2 - Новый кс. Cтарый я
13:10
Marmok
Рет қаралды 2,8 МЛН
🎈🎈🎈😲 #tiktok #shorts
0:28
Byungari 병아리언니
Рет қаралды 4,5 МЛН
How to parse and validate a number in C
10:16
CodeVault
Рет қаралды 7 М.
The Dark Side of .reserve()
18:50
Logan Smith
Рет қаралды 158 М.
String In Char Array VS. Pointer To String Literal | C Programming Tutorial
9:58
Rust Functions Are Weird (But Be Glad)
19:52
Logan Smith
Рет қаралды 147 М.
Understanding the For Loop (examples in C)
18:37
Jacob Sorber
Рет қаралды 18 М.
This is Why Programming Is Hard For you
10:48
The Coding Sloth
Рет қаралды 1 МЛН
C user input ⌨️
6:58
Bro Code
Рет қаралды 62 М.
Sigma girl VS Sigma Error girl 2  #shorts #sigma
0:27
Jin and Hattie
Рет қаралды 124 МЛН