Re: Fill structure's fields in a loop ?
- From: Richard Heathfield <rjh@xxxxxxxxxxxxxxx>
- Date: Thu, 21 Jun 2007 13:39:47 +0000
oliv29@xxxxxxxxx said:
On Jun 21, 2:46 pm, Richard Heathfield <r...@xxxxxxxxxxxxxxx> wrote:
oli...@xxxxxxxxx said:
<snip>
Ok, first of all.. i forgot to mention: that _gets is actually a
non portable version of standard C gets() function.
So what? Your code didn't call _gets(). It called gets(). So your
objection is spurious.
My code, CALLED _gets(). The code i entered HERE didnt called
_gets(). Come on, man...it was a typing mistake.
We're not psychic. We assume the code you post is the code about which
you're inviting comment. If you don't want us to waste our time and
yours debugging typos, use copy and paste rather than re-typing your
code.
Second, what's the
problem with gets() in getting a string from stdin?
It's a security breach. gets() is impossible to use safely, because
you have no way to protect your buffer from accidental or malicious
overruns. This is how the 1988 Worm brought down a big chunk of the
Internet in a very short time. Don't Do That.
Ok, i understand this. The thing is that, in my code i used, as i
said a nonportable version of gets(), with 2 parameters. The second
parameter is the maximum input of characters from stdin (the maximum
no. of chars that you are allowed to enter). So this version is safer
than standard gets(). Or is something else that you were referring
at ?
If you have a question about non-portable implementation library
functions, you need to ask them in a newsgroup that deals with that
implementation. Here, we discuss standard C, not extensions.
And if you are such and expert in C
No matter what else you may think about him, Richard Bos is certainly
an expert in C, and you would be wise to listen to him instead of
trying to argue with him.
I don't think anything about anyone.I don't know Richard Bos and if he
is, or not an expert.
He is.
I'm just a regular guy who tries to get an
answer from someone who is willing to help other people on a free web
site especially designed for this purpose,
Then I suggest you find a Web site especially designed for that purpose.
Usenet is *not* a Web site, and that remains true even if you happen to
have found a Web-based gateway to Usenet. Usenet uses the NNTP protocol
and port 119, whereas the Web uses the HTTP protocol and port 80.
so as a consequence, i
don't like this attitude (qoute: "Don't bloody use gets()! Don't they
teach the children basic road safety
anymore?"). Since i'm not his student, and he is not my teacher, a
little respect is necessary from his side.
Respect must be earned. Richard Bos has earned respect on this newsgroup
over a period of many years, because of his expertise in C and his
willingness to provide high-quality help to comp.lang.c subscribers (at
no charge, I might add). He is under no *obligation* to give you the
fluffy-bunny treatment. If you want fluffy-bunny, you'll need to spend
more time researching your problem, to demonstrate that you're not
using this wonderful comp.lang.c resource as a substitute for thinking
about the problem yourself.
why don't you make a recommandation about that
matter, explaining the difference ?
Because this newsgroup's archives are already chock-full of
explanations about why calling gets() is dumb and what you should
call instead. So if you want to know (and you *should* want to know),
go check the archives.
Believe me, the first thing i do when i need something is to
search for it! I didnt't find it (if you find a similar question to my
question (not about gets()) on this group, please let me know) so i
posted 'again'...Is that such a terrible thing ?
The comment on explanations about gets() was in response to your asking
why Richard Bos didn't explain why gets() is bad and what to use
instead. With regard to your *original* question, you did the right
thing in checking out whether the question had been asked before.
It has, actually, but I can hardly blame you for not finding it, since
it's so difficult to think up the right search terms, and anyway Google
Groups (which, for all its faults, has the least incomplete clc
archive) has gone downhill in recent years, making it much harder to
search for useful information than it used to be.
Having said all that, I'll now answer your original question.
Outside your main loop, set up an array of pointers, like this:
char *fldn[3];
fldn[0] = rec.field1;
fldn[1] = rec.field2;
fldn[2] = rec.field3;
You can now use fldn[n], in a loop, to access the char arrays of the rec
object.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
.
- Follow-Ups:
- Re: Fill structure's fields in a loop ?
- From: oliv29@xxxxxxxxx
- Re: Fill structure's fields in a loop ?
- References:
- Fill structure's fields in a loop ?
- From: oliv29@xxxxxxxxx
- Re: Fill structure's fields in a loop ?
- From: Richard Bos
- Re: Fill structure's fields in a loop ?
- From: oliv29@xxxxxxxxx
- Re: Fill structure's fields in a loop ?
- From: Richard Heathfield
- Re: Fill structure's fields in a loop ?
- From: oliv29@xxxxxxxxx
- Fill structure's fields in a loop ?
- Prev by Date: Re: SOURCE CODE FOR DIGITAL CLOCK IN C LANGUAGE
- Next by Date: Re: Why leave the error handling to the caller?
- Previous by thread: Re: Fill structure's fields in a loop ?
- Next by thread: Re: Fill structure's fields in a loop ?
- Index(es):
Relevant Pages
|