From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2261 invoked by alias); 25 Jan 2011 12:18:00 -0000 Received: (qmail 2172 invoked by uid 22791); 25 Jan 2011 12:17:59 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from mail-iw0-f175.google.com (HELO mail-iw0-f175.google.com) (209.85.214.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 25 Jan 2011 12:17:55 +0000 Received: by iwn8 with SMTP id 8so5325549iwn.20 for ; Tue, 25 Jan 2011 04:17:53 -0800 (PST) MIME-Version: 1.0 Received: by 10.42.179.71 with SMTP id bp7mr6550012icb.68.1295957873502; Tue, 25 Jan 2011 04:17:53 -0800 (PST) Received: by 10.42.230.66 with HTTP; Tue, 25 Jan 2011 04:17:53 -0800 (PST) In-Reply-To: <1295953744.24086.0.camel@jonspc> References: <1295953744.24086.0.camel@jonspc> Date: Tue, 25 Jan 2011 12:18:00 -0000 Message-ID: Subject: Re: sscanf trouble From: Jonathan Wakely To: jon@jonshouse.co.uk Cc: gcc-help@gcc.gnu.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2011-01/txt/msg00361.txt.bz2 On 25 January 2011 11:09, Jonathan Andrews wrote: > Hi people. > > Can anyone help with what should be a simple problem. I have some text > in the following form. Its a temperature reading from a wireless sensor, > the format is T=3D checksum> > > T1=3D18.0XX\n\r > > Some examples: > > =A0 =A0 =A0 =A0T1=3D-11.5 =A0 =A0 =A0 =A0EA > =A0 =A0 =A0 =A0T1=3D24.0 =A0 =A0 =A0 =A0 9D > > Im trying to convert this string into a sensor ID, a floating point > reading and a checksum as 3 variables using sscanf > > sscanf(line,"T%d=3D%f\t\t%X",&sensorid,&temperature,&checksum); > > No amount of variations on a theme seem to give me an entire decode > here, seems the equals seems to screw things up. =A0Anyone any ideas how I > can make this work? > > Thanks for any advice, > Jon This is just a general C question, unrelated to gcc, so there are more relevant places to ask. Asking C language questions on a compiler list is like asking a car manufacturer for directions: gcc is just a tool you use to compile C. Anyway ... All you've said is something is screwed up, so it's no obvious what is happening and why it doesn't match what you expect. The sscanf call should work, as long as 'line' really does match the format you expect, sensorid is an int, checksum is an unsigned int, and temperature is a float (not a double.)