I'm trying to check type of my variable with function scanf. It works fine for Dev C++(my input is int), but it doesn't using Borland. Here is what I've tried:
AnsiString as = Edit1->Text;
string b = as.c_str();
int testb = atoi(b.c_str());
if(scanf("%i", &testb)==1){
do sth;
}
Any ideas?
[edit1] moved from comment by Spektre
I have another problem. My input value should look like xx-xx-xxxx
so it's a date.
I have to check if day, month and year are integer.
I tried like this:
AnsiString a = Edit1->Text;
date = a.c_str();
if (a==AnsiString().sprintf("%i",atoi(a.SubString(0,2).c_str()))
&& a==AnsiString().sprintf("%i",atoi(a.SubString(3,2).c_str()))
&& a==AnsiString().sprintf("%i",atoi(a.SubString(6,4).c_str())) )
{
//do sth
}
- but it check only a day. Does anyone know why? – J. B. 20 hours ago
I do it in this way
s.ToInt()
is also so buggy but at least until BDS2006s.ToDouble()
for invalid number then an unmaskable exception is thrown0.98
and the decimal point is not set to.
your program crashes (atoi and atof are safe)you can also use sprintf: