slurping in binary data

J

James Kuyper

George said:
Yikes. My references appear to be outdated here.

The 'vscanf' family of functions is new in C99.

....
The snprintf() family is also new in C99.
 
J

James Kuyper

Nick said:
and it what way are the definitions of the scanf() functions
"ambiguous"? I don't think they are ambiguous therefore I don't
think they need disambiguating. Do you simply mean you don't
know what scanf/sscanf/fscanf do?

I think he means that he's not very aware of the differences between them.
 
G

George

The 'vscanf' family of functions is new in C99.

...

The snprintf() family is also new in C99.

That's good to know from a source more authoratative than my outdated
references. I was hoping to get your opinion on q2 and q3.
--
George

I believe a marriage is between a man and a woman.
George W. Bush

Picture of the Day http://apod.nasa.gov/apod/
 
I

Ian Collins

George said:
That's good to know from a source more authoratative than my outdated
references. I was hoping to get your opinion on q2 and q3.

Doesn't your platform have documentation? If not, upgrade to one that does!
 
J

James Kuyper

George said:
That's good to know from a source more authoratative than my outdated
references. I was hoping to get your opinion on q2 and q3.

Nick's answer to q2 was perfectly correct; unlike CBFalconer, I bother
to check what other people have already answered before I post my own
answer.

q3 is not only a Fortran question, but a question about recent
developments in Fortran. I'm not competent to comment on that question.

Fortran I was my first programming language, I learned it in High
School. I've done paid programming in Fortran IV, Fortran 77, and VMS
Fortran, but I haven't written a Fortran program since 1994. I've done
very minor maintenance programming on some Fortran 90 code, and I know
just enough about more recent developments in Fortran to realize that I
would need a serious refresher course before going back to Fortran.
 
G

George

all the ones that don't start with v

Huh? Are you sure?
q2)  What can a variadic function do that a garden-variety function can't?

take a [variable] number of arguments

But what good is it? Have you ever used a variadic function and said,
"whew it was a good thing I had that variadic function because ______."
I've no idea what "optional value arguments" are

An example from Adams is:

subroutine do_something( ...other arguments..., tolerance)
real, optional, intent(in) :: tolerance
...
if (present(tolerance)) then
tolerance_local = tolerance
else
tolerance_local = .001
endif

...
line 42 reverses the polarity of the rabbit

Silly rabbi, kicks are for trids.

You have to divine what a subroutine does by clues likes 'f','d', and 's'
in its name. Then you read the subroutine to see if you guessed correctly.
If you don't guess correctly soon, it turns into a long night.
I don't see why it needs a funny name it same like basic
good programming practice that applies to any programming
language.

<snip>

#include <stdio.h>
#include <stdlib.h>

#define PATH "george.txt"
#define NUMBER 100
#define BIN 1000
#define MAXFMTLEN 2000

int main(void)
{
FILE *fp;
char pattern[MAXFMTLEN];
char lnumber[NUMBER];
char lbin[BIN];
char line[MAXFMTLEN];

/*int line_num;
char data[32];*/

if ((fp = fopen(PATH, "r")) == NULL ) {
fprintf(stderr, "can't open file\n");
exit(1);
}

sprintf(pattern, "%%%ds %%%ds", BIN-1, NUMBER-1);

Can you explain this sprintf?

--
George

I believe the most solemn duty of the American president is to protect the
American people. If America shows uncertainty and weakness in this decade,
the world will drift toward tragedy. This will not happen on my watch.
George W. Bush

Picture of the Day http://apod.nasa.gov/apod/
 
G

George

Doesn't your platform have documentation? If not, upgrade to one that does!

I must think of platform as something different than you do. I think I'm
on the windows platform using gcc for windows as an implementation.

snprintf() in windows documentation makes no sense. I've been taking steps
to getting on the gcc mailing list, it just hasn't happened yet.
--
George

Now, there are some who would like to rewrite history - revisionist
historians is what I like to call them.
George W. Bush

Picture of the Day http://apod.nasa.gov/apod/
 
K

Keith Thompson

George said:
I must think of platform as something different than you do. I think I'm
on the windows platform using gcc for windows as an implementation.

snprintf() in windows documentation makes no sense. I've been taking steps
to getting on the gcc mailing list, it just hasn't happened yet.

I fail to see how the gcc mailing list would be helpful here. gcc
doesn't provide an implementation of snprintf; that's part of the
standard library. (gcc is a compiler, not a complete implementation.
It uses whatever C library is available on the system. This may or
may not be glibc, which is a separate GNU project.)

Get a copy of H&S5 (Harbison & Steele, 5th edition).

Get a copy of the latest draft of the C99 standard,
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf which is
less user-friendly, but has the virtue of being free.
 
K

Keith Thompson

George said:
On Sat, 22 Nov 2008 12:02:32 GMT, James Kuyper wrote: [...]
vfscanf
vscanf
vsscanf
swscanf
fwscanf
vfwscanf
vswscanf
vwscanf
wscanf

To decode those names: a prefix of 'f' means that it reads from a
specified file, 's' reads from a character string, and if neither is
present it reads from stdin. A prefix of 'v' means that  takes a va_list
argument instead of a variable argument list, and a 'w' means that it
reads from a wchar_t source instead of a char source.

Yikes.  My references appear to be outdated here.  I haveno reason to go
with something other than fgets/sscanf for this little project, but since
you've created this list, maybe you could comment on a couple questions.

I'm very interested in c/fortran interop, and one of the things that you
can't call as per F03 is a C function that is variadic.  

q1) Which of the above are variadic?

all the ones that don't start with v

Huh? Are you sure?

He probably is. Why are you skeptical? The functions whose names
start with 'v' take an argument of type va_list.
q2)  What can a variadic function do that a garden-variety function can't?

take a [variable] number of arguments

But what good is it? Have you ever used a variadic function and said,
"whew it was a good thing I had that variadic function because ______."

Imagine doing the equivalent of:

printf("x = %d, s = \"%s\", p = %p\n", x, s, p);

without a variadic function. It would probably look something like
this:

print_string("x = ");
print_int(x);
print_string(", s = \"");
print_string(s);
print_string("\", p = ");
print_pointer(p);
print_string("\n");

And even that doesn't let you do the equivalent of "%02d" or "%-10s".

[...]
[...]

You have to divine what a subroutine does by clues likes 'f','d', and 's'
in its name. Then you read the subroutine to see if you guessed correctly.
If you don't guess correctly soon, it turns into a long night.

If you're guessing, you're doing it wrong. If you don't know what a
given function in the C standard library does, *look it up*. Several
good sources of documentation, many of them free, have already been
pointed out to you.

[...]
#include <stdio.h>
#include <stdlib.h>

#define PATH "george.txt"
#define NUMBER 100
#define BIN 1000
#define MAXFMTLEN 2000

int main(void)
{
FILE *fp;
char pattern[MAXFMTLEN];
char lnumber[NUMBER];
char lbin[BIN];
char line[MAXFMTLEN];

/*int line_num;
char data[32];*/

if ((fp = fopen(PATH, "r")) == NULL ) {
fprintf(stderr, "can't open file\n");
exit(1);
}

sprintf(pattern, "%%%ds %%%ds", BIN-1, NUMBER-1);

Can you explain this sprintf?

It looks like it's using sprintf to generate a format string.

"%%" is replaced by a single '%' character. "%d" is replaced by an
argument of type int, converted to decimal. "%ds" is simply "%d"
followed by a literal 's'. So the above should store the following
string in pattern:

"%999s %99s"

(I just tried it after writing the above, and yes, that's what it
does.)

My guess is that pattern is used later in a call to fscanf, but I
can't be sure.
 
C

CBFalconer

James said:
George wrote:
.... snip ...


Nick's answer to q2 was perfectly correct; unlike CBFalconer, I
bother to check what other people have already answered before
I post my own answer.

Why bother? If the message to which you are replying is reasonably
composed, it already quotes all the necessary references. And any
independent messages you may happen to see may not now, or ever, be
visible to other readers. You seem to feel that answering a
message requires first reviewing something like 100 (maybe more,
maybe less) other messages hooked to the same thread.

And, if you do mention such things as my habits in order to
criticize, it would appear to be reasonable to quote the allegedly
failed reply, etc. Notice that your message is rather meaningless,
since it appears to revolve around the entities q2 and q3, which
are undefined, are mentioned as being questioned, without stating
the questions, etc.

There does not appear to be any dictum against applying
intelligence to message quoting.
 
G

George

I fail to see how the gcc mailing list would be helpful here. gcc
doesn't provide an implementation of snprintf; that's part of the
standard library. (gcc is a compiler, not a complete implementation.
It uses whatever C library is available on the system. This may or
may not be glibc, which is a separate GNU project.)

But I lack the experience to keep them separate. gfortran, for example, is
implemented with c. When I subscribed to them, I thought I was getting
flashbacks.

Nate Eldridge informed me of the gcc mailing list option to digest them, so
they end up as one e-mail a day. I do not fail to see how the gcc mailing
list will be helpful.

I think it's the appropriate response to when someone tells you to RTFM.

Get a copy of H&S5 (Harbison & Steele, 5th edition).

My Minnesota attorney insulted me today, so this will be what Santa wants
under george's tree for Christmas.
Get a copy of the latest draft of the C99 standard,
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf which is
less user-friendly, but has the virtue of being free.

I've got it. It's the only standard I've spent almost as much time with as
the fortran standard. While I've got your attention, I'd like to see the
same no bullshit definitions that you have in the fortran standard, eg:

datum : a single piece of information

data: plural of datum


--
George

I am mindful not only of preserving executive powers for myself, but for
predecessors as well.
George W. Bush

Picture of the Day http://apod.nasa.gov/apod/
 
I

Ian Collins

George said:
I must think of platform as something different than you do. I think I'm
on the windows platform using gcc for windows as an implementation.
I was referring to Unix man pages. I don't know how people can work
(especially without internet connectivity) on a platform without "man".
 
K

Keith Thompson

George said:
But I lack the experience to keep them separate. gfortran, for example, is
implemented with c. When I subscribed to them, I thought I was getting
flashbacks.

Nate Eldridge informed me of the gcc mailing list option to digest them, so
they end up as one e-mail a day. I do not fail to see how the gcc mailing
list will be helpful.

You were asking about snprintf, or at least commenting on the lack of
good documentation for it. Since gcc doesn't provide snprintf, I fail
to see how subscribing to the gcc mailing list will be helpful with
the specific problem of finding documentation for snprintf. It may
well be helpful for other purposes, and I didn't mean to imply
otherwise.

Incidentally, I think the gcc lists are gatewayed to Usenet; I see at
least gnu.gcc.announce, gnu.gcc.bug, and gnu.gcc.help on my server.
I think it's the appropriate response to when someone tells you to RTFM.

Sorry, you think *what* is the appropriate response?

Very often, the most appropriate response is simply to RTFM.
My Minnesota attorney insulted me today, so this will be what Santa wants
under george's tree for Christmas.


I've got it. It's the only standard I've spent almost as much time with as
the fortran standard. While I've got your attention, I'd like to see the
same no bullshit definitions that you have in the fortran standard, eg:

datum : a single piece of information

data: plural of datum

There's not much I can do about that. If you find something in the
standard unclear, especially if you provide improved wording,
comp.std.c would be the place to post. But remember that the standard
isn't intended to be a tutorial (neither is H&S5, but it's a friendly
reference than the standard is). But if you have trouble
understanding something in the standard, this is the place to ask
(since you'd be asking about the C language as described by the
standard, rather than about the standard itself as a document).
 
G

George

Why bother? If the message to which you are replying is reasonably
composed, it already quotes all the necessary references. And any
independent messages you may happen to see may not now, or ever, be
visible to other readers. You seem to feel that answering a
message requires first reviewing something like 100 (maybe more,
maybe less) other messages hooked to the same thread.

And, if you do mention such things as my habits in order to
criticize, it would appear to be reasonable to quote the allegedly
failed reply, etc. Notice that your message is rather meaningless,
since it appears to revolve around the entities q2 and q3, which
are undefined, are mentioned as being questioned, without stating
the questions, etc.

There does not appear to be any dictum against applying
intelligence to message quoting.

James' nonresponse to q2 made me look at Nick's last post, which I had not
seen. Apparently, life goes on without me, as I spend hours in line,
waiting for American emergency health care. I covered a hundred pages in
_Fortran 2003_.

It's important for an OP that he read every message in the tree, else he is
not editor in chief. Coming off a concussion and 2 sprained hands, I was
happy to have someone to pinch-edit for me.

What does Keith mean with:

%- He probably is. Why are you skeptical? The functions whose names
%- start with 'v' take an argument of type va_list.
--
George

I think we ought to raise the age at which juveniles can have a gun.
George W. Bush

Picture of the Day http://apod.nasa.gov/apod/
 
S

Sjouke Burry

Ian said:
I was referring to Unix man pages. I don't know how people can work
(especially without internet connectivity) on a platform without "man".
Lots of people work with something called a "BOOK" or "MANUAL".
You should try it. You might get hooked. :)
 
G

George

You were asking about snprintf, or at least commenting on the lack of
good documentation for it. Since gcc doesn't provide snprintf, I fail
to see how subscribing to the gcc mailing list will be helpful with
the specific problem of finding documentation for snprintf. It may
well be helpful for other purposes, and I didn't mean to imply
otherwise.

No, I wasn't asking about this function which I don't know, but I would
believe that someone had a relevant reason to bring it up.
Incidentally, I think the gcc lists are gatewayed to Usenet; I see at
least gnu.gcc.announce, gnu.gcc.bug, and gnu.gcc.help on my server.

What I can't figure out is how to "post" to a mailing list. I change my
e-mail approximately every five months. I would *much rather* have a news
solution as opposed to an e-mail soln.

Sorry, you think *what* is the appropriate response?

Very often, the most appropriate response is simply to RTFM.


I arrived here in albuquerque and finally encountered the manual. Ron is
the R and 1966 is the year.

The f part is something I'vebeen thinking about. In chuck's ggets, he has
a file * f. Since we all know that gets() takes from stdin, I was
thinkingabouthow to achieve this minimalism.

Is it:

#include<stdio.h>

int main(){
extern FILE * stdin;

call ggets( char*, stdin)

But f is for file pointer. int main yields 'tm'

Puttong them together in order of appearance could produce 'rftm'.

If one believes that another is suficently wrong that he needs to say, "
consult a non-existent user's manual," maybe its usual non-existence would
be by acknowledged that another has something with F and T flipped. Hence
I endorse:

RFTM
There's not much I can do about that. If you find something in the
standard unclear, especially if you provide improved wording,
comp.std.c would be the place to post. But remember that the standard
isn't intended to be a tutorial (neither is H&S5, but it's a friendly
reference than the standard is). But if you have trouble
understanding something in the standard, this is the place to ask
(since you'd be asking about the C language as described by the
standard, rather than about the standard itself as a document).

You can advocate for a better dictionary of terms.


--
George

We've climbed the mighty mountain. I see the valley below, and it's a
valley of peace.
George W. Bush

Picture of the Day http://apod.nasa.gov/apod/
 
K

Keith Thompson

George said:
What does Keith mean with:

%- He probably is. Why are you skeptical? The functions whose names
%- start with 'v' take an argument of type va_list.

It's difficult to tell without seeing the context. Fortunately, I
have a copy of the article.

James Kuyper had posted a list of the *scanf function names:
vfscanf
vscanf
vsscanf
swscanf
fwscanf
vfwscanf
vswscanf
vwscanf
wscanf

You asked:
q1) Which of the above are variadic?

Nick Keighley replied:
all the ones that don't start with v

And you replied:
Huh? Are you sure?

Your question implied some doubt about the correctness of Nick's
answer, or at least surprise. I didn't, and still don't, understand
your reaction.

And this all would have been a lot easier if you'd responded to the
actual article.
 
C

CBFalconer

Keith said:
.... snip ...

There's not much I can do about that. If you find something in
the standard unclear, especially if you provide improved wording,
comp.std.c would be the place to post. But remember that the
standard isn't intended to be a tutorial (neither is H&S5, but
it's a friendly reference than the standard is). But if you have
trouble understanding something in the standard, this is the
place to ask (since you'd be asking about the C language as
described by the standard, rather than about the standard itself
as a document).

From the C standard, which may help:

7.19.6.5 The snprintf function

Synopsis
[#1]
#include <stdio.h>
int snprintf(char * restrict s, size_t n,
const char * restrict format, ...);

Description

[#2] The snprintf function is equivalent to fprintf, except
that the output is written into an array (specified by
argument s) rather than to a stream. If n is zero, nothing
is written, and s may be a null pointer. Otherwise, output
characters beyond the n-1st are discarded rather than being
written to the array, and a null character is written at the
end of the characters actually written into the array. If
copying takes place between objects that overlap, the
behavior is undefined.
 
C

CBFalconer

George said:
Keith Thompson wrote:
.... snip ...


What I can't figure out is how to "post" to a mailing list. I
change my e-mail approximately every five months. I would *much
rather* have a news solution as opposed to an e-mail soln.

Investigate gmane. I don't change my email address.

Some free news servers. I use motzarella and gmane.
<http://www.teranews.com> (1 time charge) (free)
<http://news.aioe.org> (free)
<http://dotsrc.org> (free)
<http://www.x-privat.org/international.php> (free)
<http://motzarella.org/?language=en> (free)
<http://dotsrc.org/usenet/>(via://dotsrc.org/usenet/)(free)
<http://gmane.org/> (mail-lists via news) (free)
<http://www.newsfeeds.com/signup.htm> (pay)
<http://www.individual.net/ (low pay)
 
C

CBFalconer

Ian said:
I was referring to Unix man pages. I don't know how people can
work (especially without internet connectivity) on a platform
without "man".

Investigate "info". A superior mechanism.
 

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

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top