Still can't believe my prof and TAs expect me to do this after two lectures of C programming beginner 💀
@PortfolioCourses2 жыл бұрын
Wow, that sounds tough! Good luck, I hope this video helped a little bit. 🙂
@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 Жыл бұрын
You're welcome Naboulsi, I'm glad you enjoyed the explanation and thank you for the positive feedback! :-)
@DaiMoscv2 жыл бұрын
Thanks a lot, I've seen your others videos too and they were all very useful!
@PortfolioCourses2 жыл бұрын
You’re welcome Bilguun! :-) And that’s excellent to hear you are finding the videos useful, thank you for sharing that feedback.
@fabianselamai64932 жыл бұрын
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?
@PortfolioCourses2 жыл бұрын
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.
@fabianselamai64932 жыл бұрын
@@PortfolioCourses ok ty !
@PortfolioCourses2 жыл бұрын
You’re welcome! :-)
@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 Жыл бұрын
Thank you very much! Your lessons are very useful and you have a good presentation of information. Nice to learn from your videos :)
@PortfolioCourses Жыл бұрын
You’re very welcome, I’m glad that you’re enjoying the videos and the presentation! :-)
@kwesiafari6052 жыл бұрын
Mind blowing
@PortfolioCourses2 жыл бұрын
I’m glad you like it! :-)
@theanguyen10152 жыл бұрын
Appreciate your video. Thanks to you that I'm able to code without breaking down
@PortfolioCourses2 жыл бұрын
You’re welcome Thea! I’m very glad to hear the videos are helping you to code. :-)
@bofa-zi4fj2 жыл бұрын
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
@PortfolioCourses2 жыл бұрын
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. :-)
@robintau1592 жыл бұрын
Wondering how it would work for checking integers in a matrix...
@PortfolioCourses2 жыл бұрын
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-NotesExperience2 жыл бұрын
Excellent tutorial... I hope you have the time to code the validation of float numbers.
@PortfolioCourses2 жыл бұрын
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.
@shuu82812 жыл бұрын
Would I be able to extract a month and date integer value if the user input is YYYY MM DD?
@PortfolioCourses2 жыл бұрын
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.
@shuu82812 жыл бұрын
@@PortfolioCourses Thank you so much! What a fast reply too lol. I'll be sure to follow your advice, great videos btw.
@PortfolioCourses2 жыл бұрын
@@shuu8281 You're welcome. 🙂 And I'm glad to hear you enjoy the videos too!
@BrianParsons-or1lv5 ай бұрын
Good stuff 👏
@PortfolioCourses5 ай бұрын
Thanks, I’m glad you liked it! :-)
@константинконстантинов-ш1п2 жыл бұрын
How to do it without all of these libraries?
@PortfolioCourses2 жыл бұрын
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. 🙂
@ZedP2 жыл бұрын
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 Жыл бұрын
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.
@MrPasa7 ай бұрын
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; }