[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] scanf and __fmt string
From: |
Gre7g Luterman |
Subject: |
Re: [avr-gcc-list] scanf and __fmt string |
Date: |
Sun, 3 Jun 2007 17:10:59 -0700 (PDT) |
--- Roger Furer <address@hidden> wrote:
> Aloha from Honolulu,
> Thanks, but there isn't much info on the format
> string itself. How is
> it structured, what does it look like, where is it
> placed? Is it just
> the bit inside the parentheses following the scanf
> statement? "scanf(
> here? );"
The format string is largely the same as that used by
printf. You can see more details here:
http://en.wikipedia.org/wiki/Printf#printf_format_placeholders
Here's an example that works for AVR:
#include <avr/io.h>
#include <stdio.h>
char FormatStr[] = "%d,%d,%d";
int main(void)
{
volatile int a, b, c;
char InStr[] = "5,10,3";
sscanf(InStr, FormatStr, &a, &b, &c);
for (;;);
}
This will parse "5,10,3" and put 5 in a, 10 in b, and
3 in c.
> I am under the impression that it is
> somewhere seperate
Nope. The AVR version of scanf puts it as the second
parameter.
> and
> is reffered to by all the scanf statements in the
> program. Please
> correct me if that is wrong.
Yup. That's wrong.
> Dave N6NZ wrote:
> >
> > But... if my experience is a guide, you will be
> sorry you ever heard of
> > scanf. It's not a very robust way to parse input.
I gotta' echo this too. scanf works and returns the
number of parameters successfully decoded, (which can
be less than 3 in the above example if InStr doesn't
closely follow %d,%d,%d, but it's not particularly
robust or configurable.
It also adds 2k to your compiled code, and for those
of us in dinky parts, that is unforgivable!
Gre7g
____________________________________________________________________________________
Get your own web address.
Have a HUGE year through Yahoo! Small Business.
http://smallbusiness.yahoo.com/domains/?p=BESTDEAL