J
john
I'm trying to use scanf() to get a string that is terminated by a
$sign:
Reading a file line that has: account number, name (terminated by
$sign) and six numbers:
000001 John Doe$ 4 5 6 7 8 9
I'm trying to read it in like so:
int ret, acct, c1, c2, c3, c4, c5, c6;
char name[21];
ret = scanf("%d %[^$] %d %d %d %d %d %d",
&acct, name, &c1, &c2, &c3, &c4, &c5, &c6);
I would think that (ret should == 8), but it's only 2.
Variables acct & name look okay, but the cN vars look like they haven't
been assigne anything.
What am I doing wrong? If I split the name into two seperate strings,
say, first and last names, it works good, but I may not have both a
first & last name on every line.
$sign:
Reading a file line that has: account number, name (terminated by
$sign) and six numbers:
000001 John Doe$ 4 5 6 7 8 9
I'm trying to read it in like so:
int ret, acct, c1, c2, c3, c4, c5, c6;
char name[21];
ret = scanf("%d %[^$] %d %d %d %d %d %d",
&acct, name, &c1, &c2, &c3, &c4, &c5, &c6);
I would think that (ret should == 8), but it's only 2.
Variables acct & name look okay, but the cN vars look like they haven't
been assigne anything.
What am I doing wrong? If I split the name into two seperate strings,
say, first and last names, it works good, but I may not have both a
first & last name on every line.