Article View: comp.std.c
Article #2059Re: "1234" ==> 1234 (char * ==> int)
From: Yiannis Papelis
Date: Thu, 13 Dec 1990 16:21
Date: Thu, 13 Dec 1990 16:21
25 lines
1408 bytes
1408 bytes
In article <1990Dec12.215359.5378@cs.utk.edu> lape@.cs.utk.edu
(Bryon S. Lape) writes:
> I need to know how to convert a string of numbers into an int.
>For example, "1234" ==> 1234. I am interested in all theories, so please
>send whatever you know or think. Also, please e-mail the responses.
>
I tried to mail this but it bounced back so:
atoi("1234") will work like it has been pointed out.
The only problem with that is that you don't get any error checking other
than a return value of 0 in which case you don't know if you parsed
zero or there was an error. On the other hand
int rcode, num;
char *s; /* the string to parse */
rcode = sscanf(s, "%d", &num);
will work and give back a reliable error code (rcode==1 -> conversion OK
rcode == 0 -> no conversion.
--
Yiannis E. Papelis -------- Electrical & Computer Engineering
yiannis@eng.uiowa.edu -------- University of Iowa
Technical Details
Message-ID:
<1990Dec13.162133.19562@ccad.uiowa.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!ns-mx!ccad.uiowa.edu!yiannisReferences:
<1990Dec12.215359.5378@cs.utk.edu> <HARKCOM.90Dec13124648@potato.pa.Yokogawa.Co.jp>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!ns-mx!ccad.uiowa.edu!yiannis From: yiannis@ccad.uiowa.edu (Yiannis Papelis) Newsgroups: comp.std.c Subject: Re: "1234" ==> 1234 (char * ==> int) Message-ID: <1990Dec13.162133.19562@ccad.uiowa.edu> Date: 13 Dec 90 16:21:33 GMT References: <1990Dec12.215359.5378@cs.utk.edu> <HARKCOM.90Dec13124648@potato.pa.Yokogawa.Co.jp> Organization: CAD-Research, U. of Iowa, Iowa City, Iowa Lines: 25