Advanced Integer Input Validation | C Programming Example

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

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.

naboulsikhalid
Автор

Still can't believe my prof and TAs expect me to do this after two lectures of C programming beginner 💀

hangminh
Автор

Thanks a lot, I've seen your others videos too and they were all very useful!

DaiMoscv
Автор

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

bofa-zifj
Автор

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.

ZedP
Автор

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.

mirengeinnocent
Автор

Thank you very much! Your lessons are very useful and you have a good presentation of information. Nice to learn from your videos :)

rubrnyx
Автор

Appreciate your video. Thanks to you that I'm able to code without breaking down

theanguyen
Автор

Excellent tutorial... I hope you have the time to code the validation of float numbers.

AI-NotesExperience
Автор

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?

fabianselamai
Автор

Wondering how it would work for checking integers in a matrix...

robintau
Автор

Would I be able to extract a month and date integer value if the user input is YYYY MM DD?

shuu
Автор

How to do it without all of these libraries?

константинконстантинов-шп
Автор

I have wrote this code. It is much more easier and does the same job.

#include <stdio.h>
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.\n");
}
} else {
printf("Invalid input. Please enter a positive integer.\n");
while ((c = getchar()) != '\n' && c != EOF) {}
}
}
int valid_input = (int)x;
printf("Your input is: %d\n", valid_input);
return 0;
}

MrPasa