I have written small C++ console application and this is source code :
#include<stdio.h>
#include<locale.h>
#include<ctype.h>
#include<stdlib.h>
void main()
{
setlocale(LC_ALL, "turkish");
int a,b,c,d;
printf("first number: ");
scanf("%d", &a);
printf("second number: ");
scanf("%d", &b);
c = a+b;
printf("Sum: : %d\n", c);
}
As you can see i'm requesting two numbers from user and than summing them. But i want to add a control which check number who enterede by user is integer?
I'll check number which typed by user and than if number isn't really a integer i will echo an error. I'm using this after every scanf but it's not working very well.
if(!isdigit(a))
{
printf("Invalid Char !");
exit(1);
}
In shortly, on a scanf action, if user type "a" it will produce an error message and program stop working. If user type a number program will continue
void main, it never was, and never will be. It'sint main, despite the fact thatreturnstatements are optional inmain(but that's the only non-voidfunction where they're optional)."turkish"seems unlikely to be the right name for the locale to me, and you don't normally need to usesetlocaleanyway.