From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,c26a0bb87e0a1da4 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!feeder.news-service.com!news.netcologne.de!newsfeed-fusi2.netcologne.de!newsfeed.straub-nv.de!noris.net!news.teledata-fn.de!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Mon, 22 Feb 2010 11:24:21 +0100 From: Georg Bauhaus User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.7) Gecko/20100111 Thunderbird/3.0.1 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Does ada have a sscanf equivalent? References: <5e46b3e8-f7ea-45a6-a884-6882f6ec8295@c16g2000yqd.googlegroups.com> In-Reply-To: <5e46b3e8-f7ea-45a6-a884-6882f6ec8295@c16g2000yqd.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <4b825b5a$0$7633$9b4e6d93@newsspool1.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 22 Feb 2010 11:24:26 CET NNTP-Posting-Host: c6680550.newsspool1.arcor-online.net X-Trace: DXC=UAK4o?@FBf\mG86`U=_nC_ic==]BZ:af^4Fo<]lROoRQ<`=YMgDjhgRHbm@c@?m5g]BhmZ On 2/22/10 10:08 AM, J.s wrote: > I am trying to translate some C code that parses a string into numbers > (both Integers and Floats) from an input file. Would it be easiest to > just import the C function or is there an Ada equivalent? (I found a > package but I don't think I understand how it works: > http://www.web-port.net/Christfried.Webers/sources/flex/s-valrea__ads.htm) Don't use this package, it is internal to this compiler, like most packages from the System.* hierchy are not intended for general use such as scanning text. Instead, have a look at the Ada.Text_IO hierachy, the generic packages for integer types and floating point types should provide the necessary subprograms. (Also note that with each basic type you get its attributes, including "attribute functions" like 'Image and 'Value.) One way I would write this is read one Line, find the index K of the first space, use IIO.Get (with string parameter Line(K .. Line'Last) to read an integer from the line starting at character index K, where IIO is an instance of Integer_IO; this moves K do the same for the following floating point numbers calling subs from an instance of Float_IO and the again employing IIO For more extensive parsing needs, for example using pattern matching, there are a number of libraries, including standard Ada ones. But they are not needed here, I think. Do you have a good text book? It should explain this in some I/O chapter. > Input file: > . . . > vert 7 0.4453125 0.416015625 9 1 > vert 8 0.453125 0.517578125 10 1 > vert 9 0.39453125 0.513671875 11 1 > . . . > C code: > . . . > if (sscanf (buff, "%s %d ( %f %f %f ) ( %f %f %f )", > joint->name,&joint->parent,&joint->pos(0), > &joint->pos(1),&joint->pos(2),&joint->orient(0), > &joint->orient(1),&joint->orient(2)) == 8){ > . . .