Variable length string and fscanf

R

raphfrk

I am compiling these 2 pieces of code and getting different results

int a = 2;
fscanf( fp , "%*s" , a , buf );
 
P

Peter Nilsson

I am compiling these 2 pieces of code and getting different
results

 int a = 2;
 fscanf( fp , "%*s" , a , buf );

-----

 fscanf( fp , "%2s" , buf );

Shouldn't they both give the same result ?

No. The * flag has a different meaning in fscanf than it does
in fprintf.
 
N

Nate Eldredge

Richard said:
You will be referring all questions to the FAQ and the C standard from
now on then I guess?

No, only those which, like this one, are immediately and unambiguously
answered by a brief and easily located passage in any relevant
reference, which the OP undoubtedly has readily available.

If the OP had said "By the way, I'm on a desert island with no books,
man pages, other documentation, or web access, and have nothing but a
Usenet feed", then I'd have given the answer. As it stands, I think
it's worthwhile for the OP to get in the habit of finding such things
himself, though I probably should have said so more politely.
 
R

raphfrk

No, only those which, like this one, are immediately and unambiguously
answered by a brief and easily located passage in any relevant
reference, which the OP undoubtedly has readily available.

I would get my info about c from the internet. I did do a search, but
frankly even the fact that you do %*s for printf isn't always covered.
As it stands, I think
it's worthwhile for the OP to get in the habit of finding such things
himself, though I probably should have said so more politely.

Ask people who are very likely to know the answer is finding the info.
 
F

Flash Gordon

I would get my info about c from the internet. I did do a search, but
frankly even the fact that you do %*s for printf isn't always covered.

You would be far better off using a decent book, such as K&R 2nd
Edition. There seems to be far more inaccurate information than accurate
on the web. Search this group for suitable recommendations.
Ask people who are very likely to know the answer is finding the info.

Only until people get bored with answering basic questions that can be
answered by looking in a decent reference.
 
N

Nate Eldredge

I would get my info about c from the internet. I did do a search, but
frankly even the fact that you do %*s for printf isn't always covered.

In which case, let me recommend that you start using a more
comprehensive reference source. Your compiler or development
environment probably came with one, for instance. Some more are
suggested at http://c-faq.com/resources/books.html .

By the way, when I searched Google for "scanf", two of the first five
hits discuss the effect of "*".
Ask people who are very likely to know the answer is finding the info.

Until they get sick of answering questions that people could answer for
themselves.
 
C

CBFalconer

I would get my info about c from the internet. I did do a
search, but frankly even the fact that you do %*s for printf
isn't always covered.


Ask people who are very likely to know the answer is finding the
info.

Try using accurate references. For C, the standard is marked C99
below. n869_txt.bz2 is a bzipped version of n869.txt, the last
standard draft available in text form.

Some useful references about C:
<http://www.ungerhu.com/jxh/clc.welcome.txt>
<http://c-faq.com/> (C-faq)
<http://benpfaff.org/writings/clc/off-topic.html>
<http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf> (C99)
<http://cbfalconer.home.att.net/download/n869_txt.bz2> (pre-C99)
<http://www.dinkumware.com/c99.aspx> (C-library}
<http://gcc.gnu.org/onlinedocs/> (GNU docs)
<http://clc-wiki.net/wiki/C_community:comp.lang.c:Introduction>
<http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>
 
J

JosephKK

That's nice. Why are you here?


All questions can be answered by yourself by using Google and reading
manuals and taking time. These groups are here to help people find
timely answers. I suggest you leave the group if its too menial for your
huge brain to encumber itself with. That or set up shop with Chuck who
you seem to share a lot of characteristics with.

Perhaps, if that is the way you think others here should behave, how
about you simply set the example and answer OP's question.
.
 
G

Guest

JosephKK said:


Unless he's completely changed his character in the last year or
two, Richard Noname doesn't do helpful. He only does snide, stupid,
and group hugs with the other trolls. (Sometimes all three at
once.) Towering hypocrisy is his to command.

So the question is this: *has* Richard Noname completely changed his
character in the last year or two? Has he suddenly started posting
useful answers to C questions?

looking through his recent profile on google groups (I don't
have the patience to do half a year!)

attack on Chuck Falconer (NTC) 2
attack on someone else (NTC) 3
troll group hug 1
are C 1
debugger obsession 1
technical opinion 2
technical and correct 2

- NTC indicates No Technical Content
- some of his technical stuff included attacks
- "are C" is one of his responses to someone who says "X isn't C"
when they mean "X isn't in the C standard"

He was gratuitiusly rude in 5 posts.
You were mentioned once.

I actually read him for his technical opinions which though
often wrong are at least interesting.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top