public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* atoi() check
@ 2004-01-28  6:16 Deshpande Bansidhar(IFIN DC AI)
  2004-01-28 21:46 ` Liguo Song
  0 siblings, 1 reply; 4+ messages in thread
From: Deshpande Bansidhar(IFIN DC AI) @ 2004-01-28  6:16 UTC (permalink / raw)
  To: 'gcc-help@gcc.gnu.org'

Hi all

I have following code.
I want to add error handler for atoi() function.

E.g. 

char *ch;
int num;

/*Read ch here*/

Num = atoi(ch);

But before calling atoi I want to make sure that ch is pointing to numberic
string. 
How should I do this. I can manually write some function to check this. But
is there
Any library function inbuilt to achieve the same ? 

Thanks & regards,
Bansidhar A. Deshpande
Software Engineer 
Infineon Technologies India Pvt. Ltd. 
Discoverer Building. 
I.T.P.L., White Field Road, 
Bangalore -560066 
Phone: +91-80-51392011   Extn : 2066
Fax: +91-80-8410012


*Disclaimer*
This e-mail and any attachments are confidential and may be subject to legal
or some other professional privilege. They are intended solely for the
attention and use of the named addressee(s). They must not be disclosed to
any person without authorization. This e-mail and any attachments are also
subject to copyright. They may only be copied or distributed with the
consent of the copyright owner. If you are not a named addressee you must
not use, disclose, retain or reproduce all or any part of the information
contained in this e-mail or any attachments. If you have received this email
by mistake please notify the sender immediately by return email and delete
or destroy all copies of the email. Any confidentiality, privilege or
copyright is not waived or lost because this email has been sent to you by
mistake.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: atoi() check
  2004-01-28  6:16 atoi() check Deshpande Bansidhar(IFIN DC AI)
@ 2004-01-28 21:46 ` Liguo Song
  2004-01-28 23:02   ` Ishwar Rattan
  0 siblings, 1 reply; 4+ messages in thread
From: Liguo Song @ 2004-01-28 21:46 UTC (permalink / raw)
  To: 'gcc-help@gcc.gnu.org'

Deshpande Bansidhar(IFIN DC AI) wrote:

>Hi all
>
>I have following code.
>I want to add error handler for atoi() function.
>
>E.g. 
>
>char *ch;
>int num;
>
>/*Read ch here*/
>
>Num = atoi(ch);
>
>But before calling atoi I want to make sure that ch is pointing to numberic
>string. 
>How should I do this. I can manually write some function to check this. But
>is there
>Any library function inbuilt to achieve the same ? 
>
>  
>
How about using strtod instead? It seems to be able to give meaningful 
respond regarding the validity of the string.

Just my 2c.


Liguo (Leo)



>Thanks & regards,
>Bansidhar A. Deshpande
>Software Engineer 
>Infineon Technologies India Pvt. Ltd. 
>Discoverer Building. 
>I.T.P.L., White Field Road, 
>Bangalore -560066 
>Phone: +91-80-51392011   Extn : 2066
>Fax: +91-80-8410012
>
>
>*Disclaimer*
>This e-mail and any attachments are confidential and may be subject to legal
>or some other professional privilege. They are intended solely for the
>attention and use of the named addressee(s). They must not be disclosed to
>any person without authorization. This e-mail and any attachments are also
>subject to copyright. They may only be copied or distributed with the
>consent of the copyright owner. If you are not a named addressee you must
>not use, disclose, retain or reproduce all or any part of the information
>contained in this e-mail or any attachments. If you have received this email
>by mistake please notify the sender immediately by return email and delete
>or destroy all copies of the email. Any confidentiality, privilege or
>copyright is not waived or lost because this email has been sent to you by
>mistake.
>
>
>
>  
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: atoi() check
  2004-01-28 21:46 ` Liguo Song
@ 2004-01-28 23:02   ` Ishwar Rattan
  0 siblings, 0 replies; 4+ messages in thread
From: Ishwar Rattan @ 2004-01-28 23:02 UTC (permalink / raw)
  To: gcc-help



On Wed, 28 Jan 2004, Liguo Song wrote:

> Deshpande Bansidhar(IFIN DC AI) wrote:
>
> >Hi all
> >
> >I have following code.
> >I want to add error handler for atoi() function.
> >
> >E.g.
> >
> >char *ch;
> >int num;
> >
> >/*Read ch here*/
> >
> >Num = atoi(ch);
   ^
   n
and
atoi() returns error when it fails, take the time to trap it.

HTH
-ishwar

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: atoi() check
@ 2004-01-28 13:43 Assinovsky, Lev
  0 siblings, 0 replies; 4+ messages in thread
From: Assinovsky, Lev @ 2004-01-28 13:43 UTC (permalink / raw)
  To: Deshpande Bansidhar(IFIN DC AI), gcc-help

As far as I know there are no builtin functions
for atoi. You can use regex function set to make sure your 
string contains at least on digit.
Regular expression: [0-9]+
----
Lev Assinovsky
Aelita Software Corporation


> -----Original Message-----
> From: Deshpande Bansidhar(IFIN DC AI)
> [mailto:Bansidhar.Deshpande@infineon.com]
> Sent: Wednesday, January 28, 2004 9:11 AM
> To: 'gcc-help@gcc.gnu.org'
> Subject: atoi() check 
> 
> 
> Hi all
> 
> I have following code.
> I want to add error handler for atoi() function.
> 
> E.g. 
> 
> char *ch;
> int num;
> 
> /*Read ch here*/
> 
> Num = atoi(ch);
> 
> But before calling atoi I want to make sure that ch is 
> pointing to numberic
> string. 
> How should I do this. I can manually write some function to 
> check this. But
> is there
> Any library function inbuilt to achieve the same ? 
> 
> Thanks & regards,
> Bansidhar A. Deshpande
> Software Engineer 
> Infineon Technologies India Pvt. Ltd. 
> Discoverer Building. 
> I.T.P.L., White Field Road, 
> Bangalore -560066 
> Phone: +91-80-51392011   Extn : 2066
> Fax: +91-80-8410012
> 
> 
> *Disclaimer*
> This e-mail and any attachments are confidential and may be 
> subject to legal
> or some other professional privilege. They are intended solely for the
> attention and use of the named addressee(s). They must not be 
> disclosed to
> any person without authorization. This e-mail and any 
> attachments are also
> subject to copyright. They may only be copied or distributed with the
> consent of the copyright owner. If you are not a named 
> addressee you must
> not use, disclose, retain or reproduce all or any part of the 
> information
> contained in this e-mail or any attachments. If you have 
> received this email
> by mistake please notify the sender immediately by return 
> email and delete
> or destroy all copies of the email. Any confidentiality, privilege or
> copyright is not waived or lost because this email has been 
> sent to you by
> mistake.
> 
> 
> 
> 
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-01-28 23:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-01-28  6:16 atoi() check Deshpande Bansidhar(IFIN DC AI)
2004-01-28 21:46 ` Liguo Song
2004-01-28 23:02   ` Ishwar Rattan
2004-01-28 13:43 Assinovsky, Lev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).