By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,641 Members | 2,110 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,641 IT Pros & Developers. It's quick & easy.

Fill structure's fields in a loop ?

P: n/a
Hello,

Can anyone tell me how do i fill a structure's fields in a for loop ?

#define MAX_FIELD_LEN 10

typedef struct
{
char field1[MAX_FIELD_LEN]; /*will store first string read from
keyboard*/
char field2[MAX_FIELD_LEN]; /*will store 2nd string read from
keyboard*/
char field3[MAX_FIELD_LEN]; /*will store 3rd string read from
keyboard*/
} RECORD;

i want to read 3 strings from stdin and assign those strings in a for
loop:

RECORD rec, *pRec;
pRec = &rec;

char tmp[3][MAX_FIELD_LEN];

for(i=0;i<3;i++);
{
gets(tmp[i], MAX_FIELD_LEN +1);

/*Here i want to fill in the fields of 'rec' struct one
field per iteration...How do i do that ?*/
}

Jun 21 '07 #1
Share this Question
Share on Google+
24 Replies


P: n/a
"ol****@gmail.com" <ol****@gmail.comwrote:
Can anyone tell me how do i fill a structure's fields in a for loop ?
You can't.
#define MAX_FIELD_LEN 10

typedef struct
{
char field1[MAX_FIELD_LEN]; /*will store first string read from keyboard*/
char field2[MAX_FIELD_LEN]; /*will store 2nd string read from keyboard*/
char field3[MAX_FIELD_LEN]; /*will store 3rd string read from keyboard*/
} RECORD;

i want to read 3 strings from stdin and assign those strings in a for
loop:

RECORD rec, *pRec;
pRec = &rec;

char tmp[3][MAX_FIELD_LEN];

for(i=0;i<3;i++);
{
gets(tmp[i], MAX_FIELD_LEN +1);
Don't bloody use gets()! Don't they teach the children basic road safety
anymore?

Besides, that's not how you call gets() in the first place.
/*Here i want to fill in the fields of 'rec' struct one
field per iteration...How do i do that ?*/
You can't. If you want to use an loop and an index, use an array instead
of a struct. If you need to use a struct, you'll have to write the
member assignments out in full.

Richard
Jun 21 '07 #2

P: n/a
On Jun 21, 1:39 pm, r...@hoekstra-uitgeverij.nl (Richard Bos) wrote:
"oli...@gmail.com" <oli...@gmail.comwrote:
Can anyone tell me how do ifilla structure'sfieldsin a for loop ?

You can't.
#define MAX_FIELD_LEN 10
typedefstruct
{
char field1[MAX_FIELD_LEN]; /*will store first string read from keyboard*/
char field2[MAX_FIELD_LEN]; /*will store 2nd string read from keyboard*/
char field3[MAX_FIELD_LEN]; /*will store 3rd string read from keyboard*/
} RECORD;
i want to read 3 strings from stdin and assign those strings in a for
loop:
RECORD rec, *pRec;
pRec = &rec;
char tmp[3][MAX_FIELD_LEN];
for(i=0;i<3;i++);
{
gets(tmp[i], MAX_FIELD_LEN +1);

Don't bloody use gets()! Don't they teach the children basic road safety
anymore?

Besides, that's not how you call gets() in the first place.
/*Here i want tofillin thefieldsof 'rec'structone
field per iteration...How do i do that ?*/

You can't. If you want to use an loop and an index, use an array instead
of astruct. If you need to use astruct, you'll have to write the
member assignments out in full.

Richard
Ok, first of all.. i forgot to mention: that _gets is actually a non
portable version of standard C gets() function. Second, what's the
problem with gets() in getting a string from stdin? And if you are
such and expert in C why don't you make a recommandation about that
matter, explaining the difference ?

Jun 21 '07 #3

P: n/a
On Jun 21, 1:49 pm, "oli...@gmail.com" <oli...@gmail.comwrote:
On Jun 21, 1:39 pm, r...@hoekstra-uitgeverij.nl (Richard Bos) wrote:
"oli...@gmail.com" <oli...@gmail.comwrote:
Can anyone tell me how do ifilla structure'sfieldsin a for loop ?
You can't.
#define MAX_FIELD_LEN 10
typedefstruct
{
char field1[MAX_FIELD_LEN]; /*will store first string read from keyboard*/
char field2[MAX_FIELD_LEN]; /*will store 2nd string read from keyboard*/
char field3[MAX_FIELD_LEN]; /*will store 3rd string read from keyboard*/
} RECORD;
i want to read 3 strings from stdin and assign those strings in a for
loop:
RECORD rec, *pRec;
pRec = &rec;
char tmp[3][MAX_FIELD_LEN];
for(i=0;i<3;i++);
{
gets(tmp[i], MAX_FIELD_LEN +1);
Don't bloody use gets()! Don't they teach the children basic road safety
anymore?
Besides, that's not how you call gets() in the first place.
/*Here i want tofillin thefieldsof 'rec'structone
field per iteration...How do i do that ?*/
You can't. If you want to use an loop and an index, use an array instead
of astruct. If you need to use astruct, you'll have to write the
member assignments out in full.
Richard

Ok, first of all.. i forgot to mention: that _gets is actually a non
portable version of standard C gets() function. Second, what's the
problem with gets() in getting a string from stdin? And if you are
such and expert in C why don't you make a recommandation about that
matter, explaining the difference ?
Anyway, thanks for your answer...

Jun 21 '07 #4

P: n/a
Le 21-06-2007, ol****@gmail.com <ol****@gmail.coma écrit*:
On Jun 21, 1:39 pm, r...@hoekstra-uitgeverij.nl (Richard Bos) wrote:
>"oli...@gmail.com" <oli...@gmail.comwrote:
Can anyone tell me how do ifilla structure'sfieldsin a for loop ?

Ok, first of all.. i forgot to mention: that _gets is actually a non
portable version of standard C gets() function.
First: the code you post uses gets, not _gets
Second: why did you not use fgets
Second, what's the
problem with gets() in getting a string from stdin?
Buffer overflow.

Marc Boyer
Jun 21 '07 #5

P: n/a
ol****@gmail.com 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.
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.
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.
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.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jun 21 '07 #6

P: n/a
On Jun 21, 2:46 pm, Richard Heathfield <r...@see.sig.invalidwrote:
oli...@gmail.com 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.

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 ?

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. 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, 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.

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 ?

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999http://www.cpax.org.uk
email: rjh at the above domain, - www.

Jun 21 '07 #7

P: n/a
ol****@gmail.com said:
On Jun 21, 2:46 pm, Richard Heathfield <r...@see.sig.invalidwrote:
>oli...@gmail.com 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.
Jun 21 '07 #8

P: n/a
On 21 Jun, 11:18, "oli...@gmail.com" <oli...@gmail.comwrote:
Hello,

Can anyone tell me how do i fill a structure's fields in a for loop ?

#define MAX_FIELD_LEN 10

typedef struct
{
char field1[MAX_FIELD_LEN]; /*will store first string read from
keyboard*/
char field2[MAX_FIELD_LEN]; /*will store 2nd string read from
keyboard*/
char field3[MAX_FIELD_LEN]; /*will store 3rd string read from
keyboard*/

} RECORD;

i want to read 3 strings from stdin and assign those strings in a for
loop:

RECORD rec, *pRec;
pRec = &rec;

char tmp[3][MAX_FIELD_LEN];

for(i=0;i<3;i++);
{
gets(tmp[i], MAX_FIELD_LEN +1);

/*Here i want to fill in the fields of 'rec' struct one
field per iteration...How do i do that ?*/
}
You can't. You would need extra initialised variables,
something like this :-

char *dest[] = { rec.field1,
rec.field2,
rec.field3 };

and a statement in the for-loop something like :-

strcpy(dest[i], tmp[i]);

But it's rather difficult to see from your posting
what properties the RECORD structure might have
that the tmp[][] array hasn't. Why did you not
simply declare :-

typedef struct
{
char field[3][MAX_FIELD_LEN];

} RECORD;

then tmp[][] is completely redundant, and your
gets() can fill in a different rec.field[i] string
each time around the for-loop.
--

Jun 21 '07 #9

P: n/a
ol****@gmail.com wrote:
On Jun 21, 2:46 pm, Richard Heathfield <r...@see.sig.invalidwrote:
>oli...@gmail.com 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.
Then what have we learned about posting the exact code you are asking
for opinions on?
Jun 21 '07 #10

P: n/a
Having said all that, I'll now answer your original question.

Outside your mainloop, 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 aloop, to access the char arrays of the rec
object.
First of all, thank you for your answer to my original question. That
was actually what i was looking for, from the beginning: a straight
answer to my question, and not observations about how proficient I'm
in C.
Second, since this discussion has gone way offtopic, let me add few
final words.
I want you and Richard Bos (i'm sorry that we're talking about him
without his approval or 'presence' if i might say) to know that my
purpose in life is NOT to become a C expert. I have many other hobbies
and purposes besides programming. I'm not some 19 years old C
programmer-wannabe that after getting tired of playing Halo on his
XBOX 360 starts asking stupid questions on this web site (excuse
me,Usenet, which uses the NNTP protocol and port 119 and NOT port
80....i'm sorry, i don't want to be sarcastic but i dont see the point
of your observations about this issue) and starts annoying the grand
master of C programming. You said, "Respect must be earned"..Totally
agree with you. But you also must treat with respect a person who know
nothing about. I know he doesn't charge posted answers on Usenet
group, and that's the normal way to do it since he's posting the
answers on this group which is free, or do i miss something ? I didnt
requested a fluffy-bunny treatment and a lollipop; just a plain answer
and a respectul attitude. That's all.

Once again thanks for your final answer!


Jun 21 '07 #11

P: n/a
ol****@gmail.com wrote On 06/21/07 09:05,:
[...]
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 ?
"Safer?" Perhaps; it's hard to tell without seeing
the documentation. From your brief description, though,
it seems likely that the way you're using it is UNsafe:
char field1[MAX_FIELD_LEN];
[...]
gets(tmp[i], MAX_FIELD_LEN +1);
Back to the original question: If you really, truly
want to loop through the struct elements, there are ways
to do it. One is to use an auxiliary array of offsets:

const size_t offsets[] = {
offsetof(RECORD, field1),
offsetof(RECORD, field2),
offsetof(RECORD, field3),
};
...
for (i = 0; i < 3; ++i) {
char *field = (char*)recPtr + offsets[i];
fgets (field, MAX_FIELD_LEN, stdin);
field[strcspn("\n")] = '\0'; /* optional */
}

A more straightforward way is to use an array to
begin with:

typedef struct {
char field[3][MAX_FIELD_LEN];
} RECORD;
...
for (i = 0; i < 3; ++i) {
fgets(recPtr->field[i], MAX_FIELD_LEN, stdin);
...
}

--
Er*********@sun.com
Jun 21 '07 #12

P: n/a
ol****@gmail.com said:

<snip>
I want you and Richard Bos (i'm sorry that we're talking about him
without his approval or 'presence' if i might say) to know that my
purpose in life is NOT to become a C expert.
You're going about it the right way. I'll help, by not bothering to
answer any more questions about it that you might have.

i'm sorry, i don't want to be sarcastic
Just as well, really. You're not very good at it.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jun 21 '07 #13

P: n/a

"bert" <be************@btinternet.comwrote in message
news:11********************@p77g2000hsh.googlegrou ps.com...
On 21 Jun, 11:18, "oli...@gmail.com" <oli...@gmail.comwrote:
>Hello,

Can anyone tell me how do i fill a structure's fields in a for loop ?

#define MAX_FIELD_LEN 10

typedef struct
{
char field1[MAX_FIELD_LEN]; /*will store first string read from
keyboard*/
char field2[MAX_FIELD_LEN]; /*will store 2nd string read from
keyboard*/
char field3[MAX_FIELD_LEN]; /*will store 3rd string read from
keyboard*/

} RECORD;

i want to read 3 strings from stdin and assign those strings in a for
loop:

RECORD rec, *pRec;
pRec = &rec;

char tmp[3][MAX_FIELD_LEN];

for(i=0;i<3;i++);
{
gets(tmp[i], MAX_FIELD_LEN +1);

/*Here i want to fill in the fields of 'rec' struct one
field per iteration...How do i do that ?*/
}

You can't. You would need extra initialised variables,
(snip)
Sure you can. It's dumb to do, but here's the (bad) solution
everyone else has ignored:

char tmp[MAX_FIELD_LEN];

for(i=0;i<3;i++);
{
MyGets(tmp, MAX_FIELD_LEN );

switch (i) {
case 0:
strcpy( rec.field1, tmp );
break;

case 1:
strcpy( rec.field2, tmp );
break;

default:
strcpy( rec.field3, tmp );
break;
}
}

--
Fred L. Kleinschmidt
Jun 21 '07 #14

P: n/a
"ol****@gmail.com" <ol****@gmail.comwrites:
[...]
Ok, first of all.. i forgot to mention: that _gets is actually a non
portable version of standard C gets() function. Second, what's the
problem with gets() in getting a string from stdin? And if you are
such and expert in C why don't you make a recommandation about that
matter, explaining the difference ?
The comp.lang.c FAQ is at <http://www.c-faq.com/>, and it's an
extremely valuable resource. You've asked question 12.23.

Look at this from our point of view. Many of us have been following
this newsgroup for years. We see progammers posting unsafe code using
gets() over and over again, and we explain why it's unsafe over and
over again. It it surprising that some of us get a little exasperated
every now and then?

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 22 '07 #15

P: n/a
"ol****@gmail.com" <ol****@gmail.comwrites:
>Having said all that, I'll now answer your original question.

Outside your mainloop, 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 aloop, to access the char arrays of the rec
object.

First of all, thank you for your answer to my original question. That
was actually what i was looking for, from the beginning: a straight
answer to my question, and not observations about how proficient I'm
in C.
[...]

You were offered some very good advice. It is the nature of this
community that, if we see a problem in posted code, we'll point it
out, even if it's not what the poster was actually asking about.

Using gets(), as you did in the code you posted (regardless of what
may have been in the code you didn't post) is a sign of an
inexperienced C programmer, i.e., one who is in need of advice on how
to program more safely. You've been given that advice. As for the
perceived lack of respect, I seriously advise you not to worry about
it. Sticks and stones and all that.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 22 '07 #16

P: n/a
Keith Thompson said:
As for the
perceived lack of respect, I seriously advise you not to worry about
it.
For my own part, I'd just like to add that I start off by assuming that
people who post questions here are bright (because they're using C) but
ignorant (which is why they're asking the question - i.e. to reduce
their ignorance level, and that's a bright thing to do, too). Of
course, the nature of the question might immediately detract from that
promising beginning (e.g. "do my homework"), but in this case it
didn't. It was a reasonable question.

It wasn't until the OP started laying into people for not showing him
respect that I started losing respect for him. And when he continued
doing it, I completed the task.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jun 22 '07 #17

P: n/a
"ol****@gmail.com" <ol****@gmail.comwrote:
On Jun 21, 2:46 pm, Richard Heathfield <r...@see.sig.invalidwrote:
oli...@gmail.com said:
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.
That'll teach you to copy, not retype. To the group, your code is the
code you posted here, not some subtly or possibly wildly different code
you may or may not have anywhere else.
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.
But there is no such function. gets() is defined in the Standard, so
that's the only gets() there is in C, and it is unsafe. Any other
function you call which is _not_ in the Standard needs to be defined
before you can expect us to talk sense about it.
The second parameter is the maximum input of characters from stdin
(the maximum no. of chars that you are allowed to enter).
IOW, it's an inferior version of fgets().
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. 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
Then go there. This is not a web site, it's a newsgroup. One of the
important difference between newsgroups and web forums is that we expect
people to take a bit of effort before posting here; and that includes
reading the relevant portions of the FAQ, and a sufficient bit of
backlog to get a feel for the group. Doing either would have told you
not to use gets(), and doing the latter would have told you to define
any non-ISO functions you use.
especially designed for this purpose, 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.
I'll respect you when you stop making mistakes which only a first-month
beginner should make. Someone who uses gets() gets the same respect from
me as someone who jaywalks straight in front of my car.

Richard
Jun 22 '07 #18

P: n/a
Richard Bos wrote:
>
.... snip ...
>
I'll respect you when you stop making mistakes which only a
first-month beginner should make. Someone who uses gets() gets
the same respect from me as someone who jaywalks straight in
front of my car.
If he's doing it in a marked pedestrian crossing, you're toast.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com

Jun 22 '07 #19

P: n/a
CBFalconer <cb********@yahoo.comwrites:
Richard Bos wrote:
>>
... snip ...
>>
I'll respect you when you stop making mistakes which only a
first-month beginner should make. Someone who uses gets() gets
the same respect from me as someone who jaywalks straight in
front of my car.

If he's doing it in a marked pedestrian crossing, you're toast.
If he's doing it in a marked pedestrian crossing, he's not jaywalking.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 22 '07 #20

P: n/a
On Fri, 22 Jun 2007 10:46:33 -0400, in comp.lang.c , CBFalconer
<cb********@yahoo.comwrote:
>Richard Bos wrote:
>>
... snip ...
>>Someone who uses gets() gets
the same respect from me as someone who jaywalks straight in
front of my car.

If he's doing it in a marked pedestrian crossing, you're toast.
Hm? Its not jaywalking if you do it at a prescribed crossing place...
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Jun 22 '07 #21

P: n/a
Mark McIntyre wrote:
On Fri, 22 Jun 2007 10:46:33 -0400, in comp.lang.c , CBFalconer
<cb********@yahoo.comwrote:
Richard Bos wrote:
>
... snip ...
Someone who uses gets() gets
the same respect from me as someone who jaywalks straight in
front of my car.
If he's doing it in a marked pedestrian crossing, you're toast.

Hm? Its not jaywalking if you do it at a prescribed crossing place...
It is if you cross against a light.

Brian

Jun 22 '07 #22

P: n/a
On Fri, 22 Jun 2007 10:46:33 -0400, CBFalconer <cb********@yahoo.com>
wrote:
>Richard Bos wrote:
>>
... snip ...
>>
I'll respect you when you stop making mistakes which only a
first-month beginner should make. Someone who uses gets() gets
the same respect from me as someone who jaywalks straight in
front of my car.

If he's doing it in a marked pedestrian crossing, you're toast.
By definition, you cannot jaywalk in a pedestrian crossing. You can
cross against the light but that is not jaywalking.
Remove del for email
Jun 22 '07 #23

P: n/a
Barry Schwarz said:
On Fri, 22 Jun 2007 10:46:33 -0400, CBFalconer <cb********@yahoo.com>
wrote:
>>Richard Bos wrote:
>>>
... snip ...
>>>
I'll respect you when you stop making mistakes which only a
first-month beginner should make. Someone who uses gets() gets
the same respect from me as someone who jaywalks straight in
front of my car.

If he's doing it in a marked pedestrian crossing, you're toast.

By definition, you cannot jaywalk in a pedestrian crossing. You can
cross against the light but that is not jaywalking.
Furthermore, you have to be in a jurisdiction where the concept of
"jaywalking" exists. In the UK, there is no such concept. People cross
the road wherever and whenever it's convenient. But then, in the UK,
drivers do not have a right, as such, to be on the road. They have a
licence, which can be withdrawn if abused. But pedestrians /do/ have a
right to be on the road (well, on most roads, anyway - motorways being
an obvious exception), and they can walk where they please. And that's
only good and proper. I wouldn't want to live in a country where your
right to move over a bit of tarmac depended on your income and your
ability to drive.

(I hasten to add that I /can/ drive! But that's not the point here.)

According to the BBC's Web site, by the way, jaywalking was legalised in
the Netherlands in 1997 (but I have no independent confirmation of
this). If that's true, Mr Bos might like to re-think his stance.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jun 22 '07 #24

P: n/a
"ol****@gmail.com" <ol****@gmail.comwrote:
# Hello,
#
# Can anyone tell me how do i fill a structure's fields in a for loop ?

Indirectly.

# #define MAX_FIELD_LEN 10
#
# typedef struct
# {
# char field1[MAX_FIELD_LEN]; /*will store first string read from
# keyboard*/
# char field2[MAX_FIELD_LEN]; /*will store 2nd string read from
# keyboard*/
# char field3[MAX_FIELD_LEN]; /*will store 3rd string read from
# keyboard*/
# } RECORD;

# RECORD rec, *pRec;
# pRec = &rec;
#
# char tmp[3][MAX_FIELD_LEN];

char *p[3] = {rec.field1, rec.field2, rec.field3};

# for(i=0;i<3;i++);
# {
# gets(tmp[i], MAX_FIELD_LEN +1);
#
# /*Here i want to fill in the fields of 'rec' struct one
# field per iteration...How do i do that ?*/

strcpy(p[i],temp[i]);

# }
#
#
#

--
SM Ryan http://www.rawbw.com/~wyrmwif/
Mention something out of a Charleton Heston movie, and suddenly
everybody's a theology scholar.
Jun 24 '07 #25

This discussion thread is closed

Replies have been disabled for this discussion.