473,386 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

for and arrays

I understand this code.

int a[5];
int b;
for (b=0;b<5;b=b+1)
int a[b];

This should take every element of the array a and set it to 1,2,3,4,5.
Great. Now for the big question. How would you work this?

int a [5][3];

And make the first element of 5 all zeros and the second element of 3 equal
to 1,2,3 ? I don't know how to work with a 2 dimensional array.

Bill
Jul 22 '08
182 4499
Keith Thompson <ks***@mib.orgwrites:
"Bill Cunningham" <no****@nspam.comwrites:
[snip]

Perhaps you and Mark Pappin can agree on a tag for the subject header
of any articles for Mark's attempts to provide you with a tutorial.
I suggest "[BC]".
That sounds like a reasonable idea, Keith.

Bill, to eliminate the potential problem of your news server expiring
the most recent posting in this thread before you've replied, and to
eliminate the actual problem of the Subject line not reflecting the
content of the posts, please add "[BC]" to the subject line of any new
thread you start that relates to our ongoing exhibition tutorial.
You'll notice that I've updated the Subject here.

Richard Heathfield <rj*@see.sig.invalidwrites:
Bill Cunningham said:

<snip>
>#include <stdio.h>

int main() {
int i;
for(i=0;i<7;i++)
printf("%i \n",i);
}
Bill, can you see the difference in structure between the template I
suggested and what you've got here?

I suggested

for (A ; B ; C) {
D
}
E

and you have written

for (A ; B ; C)
F

I suggested that you print the value of i and the space within the
body of the loop, and then print the newline after the loop finishes.
You printed each of those 3 things within the body of the loop. You
also used the "no curly brackets" form of the loop and no indentation
which may in fact be contributing to your confusion over what happens
when.

I would recommend that until your skill level goes way up you
should use curly brackets around the body of every loop, conditional,
etc. that you write - this will help to reinforce the idea of
structure for you. Thus, always write

for (A ; B ; C) {
D
}
E

and never

for (A ; B ; C)
D
E

even if 'D' is just a single statement.

Just in case you're confused about what the 'for' construct does: the
above will first do 'A', then it will test if 'B' is zero - if it is,
then the loop finishes, but if not then it will do 'D', and then 'C',
and back to the test. After the loop finishes (that is, 'B' is found
to be equal to zero), then 'E' will be run. (If this is unclear, tell
me - otherwise, I will assume that you understand it in full.)
Likewise, stick with

if (A) {
B
}
else {
C
}

(once we start writing code using 'if') instead of

if (A)
B
else
C

For the purposes of this tutorial I recommend that you indent your
code as I have done here, and at least 2 spaces per level. After
you're more competent at writing actual code is the time for you to
worry about the pros and cons of different indentation styles - right
now we need to reinforce the structure of the code inside your head,
and keep it understandable for those of us who have to read what you
write.

>Hum. Now I didn't expect that. I expected the numbers to be printed
horizontally.
I see that you've later realized why your output appears in a vertical
column instead of a horizontal row. Please have another go at posting
a complete program that prints a single line containing the digits 0
through 6 inclusive, separated by spaces, followed by a newline
character. Once you've managed to regurgitate that (and that is all
this initial bit will be: learning some common patterns by rote until
you have them internalized), I'll give you another couple of problems
to work on, that use what we've done so far and add a little bit at a
time to it.

mlp
Jul 28 '08 #51
Ben Bacarisse wrote:
"Default User" <de***********@yahoo.comwrites:

<snip>
Riley is a troll.

For the record, I don't use the term myself. It is too easy to throw
around and too hard to decide in all the cases where it matters.
You're free to feel that way. Actions speak louder than words. Riley,
along with Kenny and Twink, have the goal to disrupt the forum.


Brian
Jul 28 '08 #52
"Default User" <de***********@yahoo.comwrites:
Ben Bacarisse wrote:
>"Default User" <de***********@yahoo.comwrites:

<snip>
Riley is a troll.

For the record, I don't use the term myself. It is too easy to throw
around and too hard to decide in all the cases where it matters.

You're free to feel that way. Actions speak louder than words. Riley,
along with Kenny and Twink, have the goal to disrupt the forum.


Brian
Which part of my sage advice to get a beginner like Bill familiar with C
data structure do you disagree with Bwian?

Tell me, do you ever offer any opinion of your own which is not directly
linked to petty net nannying? Every group has one - and you're the c.l.c
one. Well done.
Jul 28 '08 #53
I apologize in advance for yet another off-topic posting, but it
may explain a lot of things (if my assumptions are correct).

In article <87************@Don-John.Messina>
Mark L Pappin <ml*@acm.orgwrote, in reply to Bill Cunningham:
>The "a-ha!" moment I'm hoping you'll [i.e., Bill will] have here ...
He may well have it, but then I suspect he will need to have it
again the next day.

At one point, Mr Cunnigham mentioned that he was on Klonopin (a
brand name for clonazepam). I suspect (given the evidence accumulated
over several years) that he still is, and has been on it for a very
long time. This particular drug has a nasty side effect: it often
causes a sort of anterograde amnesia, making it impossible to learn
new things. (Depending on the degree of effect, some new things
might be learned over time, but not much, and not quickly.)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: gmail (figure it out) http://web.torek.net/torek/index.html
Jul 28 '08 #54
Chris Torek <no****@torek.netwrites:
I apologize in advance for yet another off-topic posting, but it
may explain a lot of things (if my assumptions are correct).

In article <87************@Don-John.Messina>
Mark L Pappin <ml*@acm.orgwrote, in reply to Bill Cunningham:
>>The "a-ha!" moment I'm hoping you'll [i.e., Bill will] have here ...

He may well have it, but then I suspect he will need to have it
again the next day.

At one point, Mr Cunnigham mentioned that he was on Klonopin (a
brand name for clonazepam). I suspect (given the evidence accumulated
over several years) that he still is, and has been on it for a very
long time. This particular drug has a nasty side effect: it often
causes a sort of anterograde amnesia, making it impossible to learn
new things. (Depending on the degree of effect, some new things
might be learned over time, but not much, and not quickly.)
In that case he is fighting a losing battle learning C as he is. He
would be far better off following a measured tutorial and reviewing the
lessons daily. Random questions to a usenet group will do him no good
whatsoever.
Jul 28 '08 #55
On 28 Jul, 02:46, Richard<rgr...@gmail.comwrote:
Ben Bacarisse <ben.use...@bsb.me.ukwrites:
"Default User" <defaultuse...@yahoo.comwrites:
Riley is a troll.
propably not. I'm sure he sincerly believes he's right

<snip>
opinion, then I agree, and that is in part why I posted. *If anyone
else had chosen to point out how a debugger is unlikely to help in
this case, I would not have felt the need.

The point is that it would.
here I have to disagree. There is no way you can know this.
Unless you have some deep insight into bill's psychology
I don't see how *anyone* (at least on comp.lang.c) can
work out what would help bill. For this reason I didn't
contradict you when you suggested examining the data structures and
program flow using a debugger. Normally I don't see the point
(yep, we disagreed on this before); but in bills' case who then
hell can tell what *might* help. May be he'll play around in gdb
and click! the light goes on. I must admit the output from raw
gdb looks a bit messy (and bill confuses easily). Mightn't a gui
based one be better for him? ddd actually draws pictures of data
structures.

He just seems to lack some basic machinary or insight into
how imperetive programming languages work. Maybe he should
learn assembler. Maybe he should learn prolog. I just don't know.

*I* think (and I have nearly as much doubt about this as your
debugger-solves-everything approach), he lacks the ability to plainly
state what he is trying to do. I've tried english, pseudo-code
and even assembler (when I was starting some insight into the
hardware was fruitful- but people vary). if you can't say
what you want how can you ever know you've acheived it? I think
some people are just mentally unequipped to program. Bill may
be one of them.

You might not see it. But you are looking
from a different, possibly equally valid, angle. I have spent a lot of
time with trainees
ah. I've spent *some* time with trainees- and not recently

and I have seen people almost as stuck as Bill.
wow
Best
way is to get them into the memory and SEE things as the program
steps. To see the string. To see the chars. To see the end of string
marker.

And if you think this advice is trolling then I am surprised.
I have found "Plain Richard" to be someone that I do not want to argue
with. *He does not try to understand other people's positions and
will, in the end, resort to claiming that he just does not believe his
opponents.

In some cases I take that stance. For example when someone assures me
they can debug 50,000 lines of foreign c code quicker from a printout
than from using an industry strength debugger. Those kind of things that
only get spouted in clc. it is nonsense. Can someone in the world? I
have no doubt someone can. Would we recommend that to someone like Bill
because some Indian Guru can? No we would not. Would we guess that 99%
can because Heathfield once spotted a bug on page one 10 years ago? No
we would not. We would advise sensible procedures to approach the
problem.
That does not mean, to me, that everything he writes
should go unchallenged. *Sometimes I want to offer an opposing view
but you will see that I am quite happy to let him have the last word.
He has explained his position and I have clarified mine.

My position here is that its the old seed versus crops thing with
Bill. Get him to teach himself the basic types. Feeling them with a
debugger is a great way. He seems to be as clueless as 6 months ago and
need to get his hands dirty.
he certainly needs *something* to get him out of his current
"methodology".
"I wonder if a for-loop would be useful here". I've floundered
but never to that extent!

I've suggested paper execution (which I suppose is a manual way
of single stepping a debugger).
Pasting in solutions for him is not helping
him -
agreed

if anything it is hindering him since he then mistakenly thinks he
knows why something is working. He doesn't. He needs to follow the
tutorial and learn how to examine his own programs for now. More
complicated things can follow.
<snip>

--
Nick Keighley

"Perilous to us all are the devices of an art deeper than we possess
ourselves."
Gandalf The Grey (discussing Windows NT)
Jul 28 '08 #56
On 27 Jul, 22:17, "Bill Cunningham" <nos...@nspam.comwrote:
"Ben Bacarisse" <ben.use...@bsb.me.ukwrote in message
news:87************@bsb.me.uk...
You were unlucky. *I have more luck, it seems. *On my system I get:
0123456?-??H.??Pt???l???H.??Pt??
Do you know why?

No I have no idea. That looks like garbage on your printout.
yes. Now think why would the program keep printing?
What tells it when to stop?

Think about it.
--
Nick Keighley
Jul 28 '08 #57
Nick Keighley <ni******************@hotmail.comwrites:
On 28 Jul, 02:46, Richard<rgr...@gmail.comwrote:
>Ben Bacarisse <ben.use...@bsb.me.ukwrites:
"Default User" <defaultuse...@yahoo.comwrites:
>Riley is a troll.

propably not. I'm sure he sincerly believes he's right

<snip>
opinion, then I agree, and that is in part why I posted. Â*If anyone
else had chosen to point out how a debugger is unlikely to help in
this case, I would not have felt the need.

The point is that it would.

here I have to disagree. There is no way you can know this.
No. Not 100%. But in a group of professionals I tend not to add caveats
to everything.
Unless you have some deep insight into bill's psychology
I don't see how *anyone* (at least on comp.lang.c) can
work out what would help bill. For this reason I didn't
Look. When I say "I know" I clearly mean "my experience suggests that it
almost certainly will help". Nothing is 100%.
contradict you when you suggested examining the data structures and
program flow using a debugger. Normally I don't see the point
(yep, we disagreed on this before); but in bills' case who then
Yes you have mentioned you do not see the point. I find this rather
strange and wonder about what experience you have had with such tools
which have left you seeing them as so useless. A lot of the feedback I
have read in c.l.c suggests to me that some the regulars (not including
you necessarily) simply have zero clue what a modern debugger can do and
how using it can dramatically shorten their development cycle. it is not
only there to "find bugs". It is there to stop the system when certain
criteria are met. Allows you to modify run time variables to "push"
certain extreme states you might want to give a test run. etc etc etc.

http://dirac.org/linux/gdb/01-Introd...hatisadebugger

But to be blunt : I can see NO negative aspects of someone like Bill
examining c strings and arrays etc in a debugger. The data examine
commands will display the types, lengths etc. he can see and modify the
data. It can be nothing but beneficial. Staring at other peoples
solutions on "paper" is clearly doing him no good whatsoever.
hell can tell what *might* help. May be he'll play around in gdb
and click! the light goes on. I must admit the output from raw
gdb looks a bit messy (and bill confuses easily). Mightn't a gui
based one be better for him? ddd actually draws pictures of data
structures.
And there are other debuggers too. It does not have to be gdb. The point
is simply that getting "down and dirty" will help. It can do NO
harm. And that is the bottom line for me.
Jul 28 '08 #58
Nick Keighley <ni******************@hotmail.comwrites:
On 27 Jul, 22:17, "Bill Cunningham" <nos...@nspam.comwrote:
>"Ben Bacarisse" <ben.use...@bsb.me.ukwrote in message
news:87************@bsb.me.uk...
You were unlucky. Â*I have more luck, it seems. Â*On my system I get:
0123456?-??H.??Pt???l???H.??Pt??
Do you know why?

No I have no idea. That looks like garbage on your printout.

yes. Now think why would the program keep printing?
What tells it when to stop?

Think about it.
Maybe even get a debugger to show the "string" a?

Then wonder why. Then look up what a c string is. Then check his "a"
meets that criteria? Maybe even use a debugger to add a 0 in the array
of chars somewhere and then print its value again? All done in a matter
of seconds with no recompilation required.

Not much thinking - more doing. Touchy feely.
Jul 28 '08 #59
Nick Keighley said:
On 28 Jul, 02:46, Richard<rgr...@gmail.comwrote:
>Ben Bacarisse <ben.use...@bsb.me.ukwrites:
"Default User" <defaultuse...@yahoo.comwrites:
>Riley is a troll.

propably not. I'm sure he sincerly believes he's right
Why are sure of that? The frequency of his exaggerations, his incorrect
claims, his hypocritical complaints about those who make certain kinds of
complaints, his mis-characterisations and mis-representations of other
people's positions, and his dabblings with other trolls in the group is
way too high to be explained by stupidity.

I have applied Hanlon's Razor, and found it blunt. The guy's a troll.

<snip>

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jul 28 '08 #60
Nick Keighley wrote:
On 28 Jul, 02:46, Richard<rgr...@gmail.comwrote:
Ben Bacarisse <ben.use...@bsb.me.ukwrites:
"Default User" <defaultuse...@yahoo.comwrites:
>Riley is a troll.

propably not. I'm sure he sincerly believes he's right
I think the evidence is well against you. Whatever his motivations,
he's made it clear that he wants to disrupt the newsgroup through his
postings.


Brian
Jul 28 '08 #61
"Default User" <de***********@yahoo.comwrites:
Nick Keighley wrote:
>On 28 Jul, 02:46, Richard<rgr...@gmail.comwrote:
Ben Bacarisse <ben.use...@bsb.me.ukwrites:
"Default User" <defaultuse...@yahoo.comwrites:
>Riley is a troll.

propably not. I'm sure he sincerly believes he's right

I think the evidence is well against you. Whatever his motivations,
he's made it clear that he wants to disrupt the newsgroup through his
postings.


Brian
You continue to add nothing to the thread. Why is that?

Is the totality of your knowledge only to wag your finger and tell
people what they can post and they can post to?

Possibly you would like to dissect what I said, not what you think I
said, and explain why any of it is NOT good advice for a new C
programmer so obviously confused by the parlance used here.
Jul 28 '08 #62
Richard<rg****@gmail.comwrites:
Nick Keighley <ni******************@hotmail.comwrites:
>On 27 Jul, 22:17, "Bill Cunningham" <nos...@nspam.comwrote:
>>"Ben Bacarisse" <ben.use...@bsb.me.ukwrote in message
news:87************@bsb.me.uk...
>You were unlucky. Â*I have more luck, it seems. Â*On my system I get:

0123456?-??H.??Pt???l???H.??Pt??

Do you know why?

No I have no idea. That looks like garbage on your printout.

yes. Now think why would the program keep printing?
What tells it when to stop?

Think about it.

Maybe even get a debugger to show the "string" a?
He won't see anything wrong. His data is terminated. he has said
so. The program is wrong but the data happens to be correct. A
debugger won't help here. I've said it before but I need to keep
saying it in case he tries and wonders why everything is OK. The
output above is from *my system* not his.

--
Ben.
Jul 28 '08 #63
Richard Heathfield <rj*@see.sig.invalidwrites:
Nick Keighley said:
>On 28 Jul, 02:46, Richard<rgr...@gmail.comwrote:
>>Ben Bacarisse <ben.use...@bsb.me.ukwrites:
"Default User" <defaultuse...@yahoo.comwrites:
>>Riley is a troll.

propably not. I'm sure he sincerly believes he's right

Why are sure of that? The frequency of his exaggerations, his incorrect
claims, his hypocritical complaints about those who make certain kinds of
complaints, his mis-characterisations and mis-representations of other
people's positions, and his dabblings with other trolls in the group is
way too high to be explained by stupidity.

I have applied Hanlon's Razor, and found it blunt. The guy's a troll.

<snip>
As I pointed out, my view that you are an obnoxious egomaniac does not,
in any shape or form, make me a troll.

You take yourself far too seriously when it suits you. You are not the
group moderator. You are not indispensable. And you are not particularly
special when it comes to help new C programmers since you're so full of
your own self importance you find it almost impossible to bring things
down to a level that the new, and often panicking, programmer can come
to deal with. Other, more open, contributors make this a far nicer group
than you could ever hope to with your mealy mouthed word games and
pedantic nit picking.

Jul 28 '08 #64
Ben Bacarisse <be********@bsb.me.ukwrites:
Richard<rg****@gmail.comwrites:
>Nick Keighley <ni******************@hotmail.comwrites:
>>On 27 Jul, 22:17, "Bill Cunningham" <nos...@nspam.comwrote:
"Ben Bacarisse" <ben.use...@bsb.me.ukwrote in message
news:87************@bsb.me.uk...

You were unlucky. Â*I have more luck, it seems. Â*On my system I get:

0123456?-??H.??Pt???l???H.??Pt??

Do you know why?

No I have no idea. That looks like garbage on your printout.

yes. Now think why would the program keep printing?
What tells it when to stop?

Think about it.

Maybe even get a debugger to show the "string" a?

He won't see anything wrong. His data is terminated. he has said
Not in the code directly linked upthread it wasn't. or the output would
not be as indicated above.
so. The program is wrong but the data happens to be correct. A
debugger won't help here. I've said it before but I need to keep
saying it in case he tries and wonders why everything is OK. The
output above is from *my system* not his.
But once more : my recommendations are about him getting a feeling for
the data. Even today we have the ridiculous nit picking about strings
not being a type but a "kind of" character array. No wonder so many
nOObs leave this place with a headache.

Jul 28 '08 #65
Richard<rg****@gmail.comwrites:
Richard Heathfield <rj*@see.sig.invalidwrites:
>Nick Keighley said:
>>On 28 Jul, 02:46, Richard<rgr...@gmail.comwrote:
Ben Bacarisse <ben.use...@bsb.me.ukwrites:
"Default User" <defaultuse...@yahoo.comwrites:
Riley is a troll.

propably not. I'm sure he sincerly believes he's right
[...]
>>
I have applied Hanlon's Razor, and found it blunt. The guy's a troll.

<snip>

As I pointed out, my view that you are an obnoxious egomaniac does not,
in any shape or form, make me a troll.
[...]

That's absolutely correct. It's not your opinion of Richard
Heathfield that makes you a troll. (Nobody has said that it is.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jul 28 '08 #66

"Ben Bacarisse" <be********@bsb.me.ukschreef in bericht
news:87************@bsb.me.uk...
Richard<rg****@gmail.comwrites:

<snip program>
>You don't know how to include spaces?

ROTFLM. It just gets better.

I don't understand this. If you think Bill is clever fiction, why are
you replying with serious suggestions (see below)? If you think he is
genuinely struggling to learn, then why laugh at his attempts. It
seems cruel.
lol cruel. If Bill's not a troll, he's REALLY masochistic! But I'm leaning
towards he's a troll but then a very funny and smart one.

Jul 28 '08 #67
On 28 Jul 2008 at 0:01, Ben Bacarisse wrote:
"Default User" <de***********@yahoo.comwrites:
>Riley is a troll.

For the record, I don't use the term myself. It is too easy to throw
around and too hard to decide in all the cases where it matters.
A sensible position. One man's troll is another man's Default Loser.

Jul 28 '08 #68
On 28 Jul 2008 at 18:24, Default User wrote:
I think the evidence is well against you. Whatever his motivations,
he's made it clear that he wants to disrupt the newsgroup through his
postings.
"Disrupt the newsgroup", huh? Why don't you count the number of positive
contributions of information and suggestions and answers to newbies'
questions from your trio of "trolls" in the last month, and compare it
to the number of times *you*'ve tried to sow genuine disruption in the
group by stirring up endless debates and ill-feeling about who is and
isn't a "troll"?

Jul 28 '08 #69

"Mark L Pappin" <ml*@acm.orgwrote in message
news:87***************@Don-John.Messina...
Keith Thompson <ks***@mib.orgwrites:
>"Bill Cunningham" <no****@nspam.comwrites:
Bill Cunningham said:

<snip>
>>#include <stdio.h>

int main() {
int i;
for(i=0;i<7;i++)
printf("%i \n",i);
}

Bill, can you see the difference in structure between the template I
suggested and what you've got here?

I suggested

for (A ; B ; C) {
D
}
E

and you have written

for (A ; B ; C)
F

I suggested that you print the value of i and the space within the
body of the loop, and then print the newline after the loop finishes.
You printed each of those 3 things within the body of the loop. You
also used the "no curly brackets" form of the loop and no indentation
which may in fact be contributing to your confusion over what happens
when.

I would recommend that until your skill level goes way up you
should use curly brackets around the body of every loop, conditional,
etc. that you write - this will help to reinforce the idea of
structure for you. Thus, always write

for (A ; B ; C) {
D
}
E

and never

for (A ; B ; C)
D
E

even if 'D' is just a single statement.

Just in case you're confused about what the 'for' construct does: the
above will first do 'A', then it will test if 'B' is zero - if it is,
then the loop finishes, but if not then it will do 'D', and then 'C',
and back to the test. After the loop finishes (that is, 'B' is found
to be equal to zero), then 'E' will be run. (If this is unclear, tell
me - otherwise, I will assume that you understand it in full.)
Likewise, stick with

if (A) {
B
}
else {
C
}

(once we start writing code using 'if') instead of

if (A)
B
else
C

For the purposes of this tutorial I recommend that you indent your
code as I have done here, and at least 2 spaces per level. After
you're more competent at writing actual code is the time for you to
worry about the pros and cons of different indentation styles - right
now we need to reinforce the structure of the code inside your head,
and keep it understandable for those of us who have to read what you
write.

>>Hum. Now I didn't expect that. I expected the numbers to be printed
horizontally.

I see that you've later realized why your output appears in a vertical
column instead of a horizontal row. Please have another go at posting
a complete program that prints a single line containing the digits 0
through 6 inclusive, separated by spaces, followed by a newline
character. Once you've managed to regurgitate that (and that is all
this initial bit will be: learning some common patterns by rote until
you have them internalized), I'll give you another couple of problems
to work on, that use what we've done so far and add a little bit at a
time to it.

mlp
I think I might have it right now Mark.
#include <stdio.h>

int main(void) {
int i;
for (i=0;i<7;i++) {
printf("%i",i);
printf(" ");
}
printf("\n");
return 0;
}

Bill

Jul 28 '08 #70
"Bill Cunningham" <no****@nspam.comwrites:
"Mark L Pappin" <ml*@acm.orgwrote:
>Please have another go at posting a complete program that prints a
single line containing the digits 0 through 6 inclusive, separated
by spaces, followed by a newline character.
I think I might have it right now Mark.
#include <stdio.h>

int main(void) {
int i;
for (i=0;i<7;i++) {
printf("%i",i);
printf(" ");
}
You have this closing-curly-bracket lined up with the start of each
line _within_ the block.
I recommended (by example) that you line up each closing-curly-bracket
with the start of the line _introducing_ the block.

I requested that for the purposes of this tutorial you follow the
indentation scheme I've used. Is there some reason you have not done
so?

You may certainly choose any scheme you like, but I thought I had made
it clear
- I believe that sticking strictly to the layout I use here will
reinforce concepts that are important to programming in C;
and
- if you don't follow my recommendations and can't back up any
deviations with sound argument then the tutorial stops.
printf("\n");
return 0;
}
Other than the [some might say minor] indentation issue, this is
exactly what I had hoped you would produce. So, on with the tutorial.

3c. Modify the above program to print the number and the space with a
single call to 'printf()' instead of two calls.
4a. Write a program to print 7 lines, each containing the line number
(start at 0), the square of the line number, and the cube of the line
number, separated by spaces.

(The square of a number is that number multiplied by itself.
The cube of a number is the number multiplied by its square.)
4b. Modify your answer for 4a to print 11 lines.

(If this requires more than changing a '7' to an '11', go back and
find another way to answer 4a, then continue.)
4c. Modify your answer for 4b to print at the end of each line another
space and the maximum value of an 'int'.

(Hint: lines like
#include <limits.h>
printf(" %d",INT_MAX);
will be involved.)
4d. Can you figure out what maximum number of lines the program could
print and still produce correct values for the square and cube? Could
that maximum be made larger, and how?
mlp
Jul 28 '08 #71

"Mark L Pappin" <ml*@acm.orgwrote in message
news:87************@Don-John.Messina...
You have this closing-curly-bracket lined up with the start of each
line _within_ the block.
I recommended (by example) that you line up each closing-curly-bracket
with the start of the line _introducing_ the block.

I requested that for the purposes of this tutorial you follow the
indentation scheme I've used. Is there some reason you have not done
so?
I used a braces scheme I'm used to. Maybe I didn't understand. How
exactly would you again like me to use the scheme you requested ? I will
look back at previous posts to see if I missed something.

Bill
Jul 29 '08 #72
Richard wrote:

<snip>
The issue is for Bill to understand the data. Nothing more. Nothing
less. We keep hearing "I dont know spaces", "I dont know string" etc
etc. Its tiresome. He needs to do some spadework.
It's my personal opinion that Bill C has become a sort of collective
obsession of CLC. I'm pretty sure he is a troll. Anyone who genuinely
has the sort of problems that he seems to display would have given up
on programming long back, or would be well advised to do so. If he
needs some sort of recreational therapy (assuming for the moment that
he *is* a genuine case), then there are plenty of better hobbies to
chose (in the sense that it would be better for *him* ) from than
grappling with C. Programming is hard enough for a normal person, I
don't know why someone like Bill must punish himself upon it.

Of course having said all this I have simply concluded that he is a
troll. The presence of the string

Message-ID: <P56jk.199$JH5.174@trnddc06>

in his headers leads me believe he is having a good laugh at the
spectacle of a whole group running around him.

Jul 29 '08 #73
santosh <sa*********@gmail.comwrites:
[...]
Of course having said all this I have simply concluded that he is a
troll. The presence of the string

Message-ID: <P56jk.199$JH5.174@trnddc06>

in his headers leads me believe he is having a good laugh at the
spectacle of a whole group running around him.
I don't understand. What is it about the Message-ID that causes you
to reach that conclusion?

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jul 29 '08 #74
Keith Thompson wrote:
santosh <sa*********@gmail.comwrites:
[...]
>Of course having said all this I have simply concluded that he is a
troll. The presence of the string

Message-ID: <P56jk.199$JH5.174@trnddc06>

in his headers leads me believe he is having a good laugh at the
spectacle of a whole group running around him.

I don't understand. What is it about the Message-ID that causes you
to reach that conclusion?
Well, he is obviously using the newsreader 'trn' setup to masquerade as
OE, isn't he?

Jul 29 '08 #75
santosh <sa*********@gmail.comwrites:
Keith Thompson wrote:
>santosh <sa*********@gmail.comwrites:
[...]
>>Of course having said all this I have simply concluded that he is a
troll. The presence of the string

Message-ID: <P56jk.199$JH5.174@trnddc06>

in his headers leads me believe he is having a good laugh at the
spectacle of a whole group running around him.

I don't understand. What is it about the Message-ID that causes you
to reach that conclusion?

Well, he is obviously using the newsreader 'trn' setup to masquerade as
OE, isn't he?
It wasn't obvious to me; I never bothered to look at the headers.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jul 29 '08 #76
Mark,

I do have a program called indent. I can run all my source through that and
have a consistant scheme of code. Otherwise does this look better?

#include <stdio.h>

int main(void) {
int i;
for (i=0;i<7;i++) {
printf("%i",i);
printf(" ");
}
printf("\n");
return 0;
}

I think it's more rreadable. Is this what you suggested?

Bill
Jul 29 '08 #77
Mark,

Well it took awhile and a lot of guessing and working with printf but I
finally got q3c.

#include <stdio.h>

int main(void) {
int i;
for (i=0;i<7;i++) {
printf("%i" " ",i);
}
printf("\n");
return 0;
}

How is the indentation on this one ?

Bill
Jul 29 '08 #78
"Bill Cunningham" <no****@nspam.comwrites:
Mark,

Well it took awhile and a lot of guessing and working with printf but I
finally got q3c.

#include <stdio.h>

int main(void) {
int i;
for (i=0;i<7;i++) {
printf("%i" " ",i);
}
printf("\n");
return 0;
}

How is the indentation on this one ?
The indentation is mostly ok, but it's inconsistent. You're using 7
columns for the body of your function, but only 2 for the body of your
for loop. I suggest you consult the documentation of indent to find a
set of options that makes the levels consistent. My personal
recommendation is 4 columns for each level.

A comment on your code. Why did you write

"%i" " "

? Do you understand exactly what that syntax means (I'm referring to
the quotation marks, not the %i). Is there a simpler and clearer way
to say exactly the same thing? (Hint: Yes, there is.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jul 29 '08 #79

"Keith Thompson" <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
A comment on your code. Why did you write

"%i" " "

? Do you understand exactly what that syntax means (I'm referring to
the quotation marks, not the %i).
Nope.

Is there a simpler and clearer way
to say exactly the same thing? (Hint: Yes, there is.)
I had no idea what I was doing. I was hoping I would get it right and
kept fiddling around with printfs' formatting til I got a space in between
each number. My text (not k&r2) said ' ' would be a space. It wasn't. I only
got number like such

'0''1''2'...

Bill

Jul 29 '08 #80
On Jul 29, 9:16 pm, Keith Thompson <ks...@mib.orgwrote:
santosh<santosh....@gmail.comwrites:
Well, he is obviously using the newsreader 'trn' setup to masquerade as
OE, isn't he?

It wasn't obvious to me; I never bothered to look at the headers.
Okay but now that it's been pointed out to you by someone, do you
still believe that Cunningham is genuine?
Jul 30 '08 #81
vi******@gmail.com writes:
On Jul 29, 9:16 pm, Keith Thompson <ks...@mib.orgwrote:
>santosh<santosh....@gmail.comwrites:
Well, he is obviously using the newsreader 'trn' setup to masquerade as
OE, isn't he?

It wasn't obvious to me; I never bothered to look at the headers.

Okay but now that it's been pointed out to you by someone, do you
still believe that Cunningham is genuine?
I have no idea. For all I know, there could be perfectly valid
reasons to have trn masquerade (poorly) as OE. (I've done similar
things with web browsers in the past, telling Opera to masquerade as
Internet Explorer.) Or the Message-ID might have been set somewhere
else. Or his X-Newsreader: header might be incorrect. Or something I
haven't thought of.

Why would a troll post with trn masquerading as OE anyway? What would
be the point? Even if there's no innocent explanation, I don't see a
plausible guilty explanation. What do you have in mind?

Bill Cunningham: Do you have any comment on this? Do you know why
your X-Newsreader: header implies you're using Outlook Express, but
your Message-ID implies you're using trn?

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jul 30 '08 #82
On Jul 30, 3:50 am, Keith Thompson <ks...@mib.orgwrote:
vipps...@gmail.com writes:
On Jul 29, 9:16 pm, Keith Thompson <ks...@mib.orgwrote:
santosh<santosh....@gmail.comwrites:
Well, he is obviously using the newsreader 'trn' setup to masquerade as
OE, isn't he?
It wasn't obvious to me; I never bothered to look at the headers.
Okay but now that it's been pointed out to you by someone, do you
still believe that Cunningham is genuine?

I have no idea. For all I know, there could be perfectly valid
reasons to have trn masquerade (poorly) as OE. (I've done similar
things with web browsers in the past, telling Opera to masquerade as
Internet Explorer.) Or the Message-ID might have been set somewhere
else. Or his X-Newsreader: header might be incorrect. Or something I
haven't thought of.

Why would a troll post with trn masquerading as OE anyway? What would
be the point? Even if there's no innocent explanation, I don't see a
plausible guilty explanation. What do you have in mind?
I can think of one: so that the troll can have an excuse for
constantly messing with the posts. (ie removing attributes, top-
posting, messing up quotes, stuff that Bill frequently does)
Why he doesn't genuinely use OE instead of "masquerading", I believe
because the troll does not use windows.
Jul 30 '08 #83
Keith Thompson wrote:
vi******@gmail.com writes:
>On Jul 29, 9:16 pm, Keith Thompson <ks...@mib.orgwrote:
>>santosh<santosh....@gmail.comwrites:
Well, he is obviously using the newsreader 'trn' setup to
masquerade as
OE, isn't he?

It wasn't obvious to me; I never bothered to look at the headers.

Okay but now that it's been pointed out to you by someone, do you
still believe that Cunningham is genuine?

I have no idea. For all I know, there could be perfectly valid
reasons to have trn masquerade (poorly) as OE. (I've done similar
things with web browsers in the past, telling Opera to masquerade as
Internet Explorer.) Or the Message-ID might have been set somewhere
else. Or his X-Newsreader: header might be incorrect. Or something I
haven't thought of.

Why would a troll post with trn masquerading as OE anyway? What would
be the point? Even if there's no innocent explanation, I don't see a
plausible guilty explanation. What do you have in mind?
One thing I must note is that the string "...@trnddc" is found only in
conjunction with Microsoft Outlook Express; I did a quick Google Groups
search. However only a minute fraction of posts from OE seem to have
this form msg-ID in the first place.

It still seems suspicious to me, but I may be making accusations without
clear evidence. In any case, regardless of the "msg-ID" issue, based on
an overall consideration of his posts to clc, I believe Bill C is a
troll. IMO of course.

<snip>

Jul 30 '08 #84
"Bill Cunningham" <no****@nspam.comwrites:
"Keith Thompson" <ks***@mib.orgwrote
>A comment on your code. Why did you write

"%i" " "

? Do you understand exactly what that syntax means (I'm referring to
the quotation marks, not the %i).

Nope.
The line Keith quotes contains two string literals, "%i" and " ",
separated by nothing but whitespace ("%i"" " or "%i" " " would be
equivalent). The compiler has (as it is required to) merged them into
a single string literal "%i " and it is this which printf() was
passed.
I had no idea what I was doing. I was hoping I would get it right
and kept fiddling around
You've been told before: Don't Do That.
If you have no idea, ask.

I'm beginning to realise how pointless my offer to help was, but I'm
the eternal optimist here: prove them wrong, Bill; work through the
exercises I've set, post the code you come up with, tell us where
you're stuck, absorb the help that's given to you, and practice,
practice, practice. But step back from the Monte Carlo programming
technique (by which I mean "throwing random characters into source
file and hoping it does what you want") that you've already discovered
many times DOES NOT WORK.
My text (not k&r2)
1. What is your text?
2. Get K&R2.
said ' ' would be a space. It wasn't.
You seem to be using English the same way you use C, stringing
together words that individually are fine but in concert are
meaningless. ' ' most certainly _is_ a space, but the way in which
you used it obviously didn't produce a space in the output - what you
should do in this case is

1. Show us the code you wrote.
2. Tell us _precisely_ what you expected it to do.
3. Tell us _precisely_ what it actually did.

mlp
Jul 30 '08 #85
On Tue, 29 Jul 2008 17:38:42 -0700 (PDT), vi******@gmail.com wrote:
>On Jul 29, 9:16 pm, Keith Thompson <ks...@mib.orgwrote:
>santosh<santosh....@gmail.comwrites:
Well, he is obviously using the newsreader 'trn' setup to masquerade as
OE, isn't he?

It wasn't obvious to me; I never bothered to look at the headers.

Okay but now that it's been pointed out to you by someone, do you
still believe that Cunningham is genuine?
I don't understand headers for the most part but after BC's recent new
percentage thread and his response to RH in the q3 tutorial thread, I
have reluctantly come to the same conclusion. Even worse, the quality
of his trolling is decreasing (almost as if he were losing interest in
stringing us along).

But it does give me a chance to test a filter feature of Agent to kill
any thread he starts.

--
Remove del for email
Jul 30 '08 #86

"Keith Thompson" <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
Bill Cunningham: Do you have any comment on this? Do you know why
your X-Newsreader: header implies you're using Outlook Express, but
your Message-ID implies you're using trn?
Keith I don't think my headers are lying. I'm running old ver 6 of OE.
slrn didn't work out for me. All the newsreaders I've tried as late I
haven't been able to lock onto my news server with.
I don't use trn at all.

Bill
Jul 30 '08 #87

"Mark L Pappin" <ml*@acm.orgwrote in message
news:87************@Don-John.Messina...
"Bill Cunningham" <no****@nspam.comwrites:
>"Keith Thompson" <ks***@mib.orgwrote
>>A comment on your code. Why did you write

"%i" " "

? Do you understand exactly what that syntax means (I'm referring to
the quotation marks, not the %i).

Nope.

The line Keith quotes contains two string literals, "%i" and " ",
separated by nothing but whitespace ("%i"" " or "%i" " " would be
equivalent). The compiler has (as it is required to) merged them into
a single string literal "%i " and it is this which printf() was
passed.
>I had no idea what I was doing. I was hoping I would get it right
and kept fiddling around

You've been told before: Don't Do That.
If you have no idea, ask.

I'm beginning to realise how pointless my offer to help was, but I'm
the eternal optimist here: prove them wrong, Bill; work through the
exercises I've set, post the code you come up with, tell us where
you're stuck, absorb the help that's given to you, and practice,
practice, practice. But step back from the Monte Carlo programming
technique (by which I mean "throwing random characters into source
file and hoping it does what you want") that you've already discovered
many times DOES NOT WORK.
>My text (not k&r2)

1. What is your text?
2. Get K&R2.
>said ' ' would be a space. It wasn't.

You seem to be using English the same way you use C, stringing
together words that individually are fine but in concert are
meaningless. ' ' most certainly _is_ a space, but the way in which
you used it obviously didn't produce a space in the output - what you
should do in this case is

1. Show us the code you wrote.
2. Tell us _precisely_ what you expected it to do.
3. Tell us _precisely_ what it actually did.

mlp
These questions in your tutorial Mark is indeed getting more difficult.
It may be several days before I can put together all the answers to all the
questions but I sill go one step at a time. I hope you are prepared to work
with me on some of these, the first answer will quite probably not be
correct. But what ever happens I certainly thank you for your attempts. I
will do my best on this.

Bill
Jul 30 '08 #88
Bill Cunningham wrote:
>
"Keith Thompson" <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
>Bill Cunningham: Do you have any comment on this? Do you know why
your X-Newsreader: header implies you're using Outlook Express, but
your Message-ID implies you're using trn?
Keith I don't think my headers are lying. I'm running old ver 6
of OE.
slrn didn't work out for me. All the newsreaders I've tried as late I
haven't been able to lock onto my news server with.
I don't use trn at all.
Well, I'm sorry for my accusations, but forgive me if I'm not as
enthusiastic about discussing C with you as I was some weeks
previously. In any case you are still getting excellent help from
several posters.

Jul 30 '08 #89

"Keith Thompson" <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
Bill Cunningham: Do you have any comment on this? Do you know why
your X-Newsreader: header implies you're using Outlook Express, but
your Message-ID implies you're using trn?
I will post my headers.

Path:
nwrddc01.gnilink.net!cyclone2.gnilink.net!cyclone1 .gnilink.net!spamkiller.gnilink.net!gnilink.net!tr nddc04.POSTED!12222bec!not-for-mail
From: "Bill Cunningham" <no****@nspam.com>
Newsgroups: comp.lang.c
References: <s_shk.374$5Q.80@trnddc06<87************@bsb.me.uk >
<prthk.376$5Q.164@trnddc06<87************@bsb.me.u k>
<foNhk.417$_l.339@trnddc04<87************@Don-John.Messina>
<Va5ik.507$_l.500@trnddc04<87************@Don-John.Messina>
<87************@bsb.me.uk<s15jk.160$wS4.87@trnddc0 3>
<g6**********@registered.motzarella.org<87******** ****@bsb.me.uk>
<g6**********@registered.motzarella.org<87******** ****@bsb.me.uk>
<g6**********@registered.motzarella.org>
<g6**********@registered.motzarella.org<ln******** ****@nuthaus.mib.org>
<g6**********@registered.motzarella.org<ln******** ****@nuthaus.mib.org>
<cd**********************************@i76g2000hsf. googlegroups.com>
<ln************@nuthaus.mib.org>
Subject: Re: for and arrays
Lines: 16
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512
Message-ID: <JM2kk.567$rb5.516@trnddc04>
Date: Wed, 30 Jul 2008 18:53:29 GMT
NNTP-Posting-Host: 71.188.198.61
X-Trace: trnddc04 1217444009 71.188.198.61 (Wed, 30 Jul 2008 14:53:29 EDT)
NNTP-Posting-Date: Wed, 30 Jul 2008 14:53:29 EDT
X-Received-Date: Wed, 30 Jul 2008 14:53:28 EDT (nwrddc01.gnilink.net)


Jul 30 '08 #90

"santosh" <sa*********@gmail.comwrote in message
news:g6**********@registered.motzarella.org...
Well, I'm sorry for my accusations,
No problem.

but forgive me if I'm not as
enthusiastic about discussing C with you as I was some weeks
previously. In any case you are still getting excellent help from
several posters.
I think that's vippstar's job.

Bill
Jul 30 '08 #91

"santosh" <sa*********@gmail.comwrote in message
news:g6**********@registered.motzarella.org...
Well, I'm sorry for my accusations, but forgive me if I'm not as
enthusiastic about discussing C with you as I was some weeks
previously. In any case you are still getting excellent help from
several posters.
Vippstar only comes out to produce problems. Almost troll like. But I
thank you for your help. You do discuss C atleast. I have posted my full
headers as a measure of good faith.

Bill
Jul 30 '08 #92
Bill Cunningham wrote:
"santosh" <sa*********@gmail.comwrote in message
news:g6**********@registered.motzarella.org...
>Well, I'm sorry for my accusations, but forgive me if I'm not as
enthusiastic about discussing C with you as I was some weeks
previously. In any case you are still getting excellent help from
several posters.

Vippstar only comes out to produce problems. Almost troll like.
But I
thank you for your help. You do discuss C atleast. I have posted my
full headers as a measure of good faith.
Bill, you are getting better help from Mark Pappin than one could
reasonably hope for. Just stick to his tutorial, however long it takes
to answer his exercises. Even a partial attempt at a solution is better
than endless debates with formatting issues and such.

Jul 30 '08 #93

"Mark L Pappin" <ml*@acm.orgwrote in message
news:87************@Don-John.Messina...
"Bill Cunningham" <no****@nspam.comwrites:
>"Keith Thompson" <ks***@mib.orgwrote
>>A comment on your code. Why did you write

"%i" " "

? Do you understand exactly what that syntax means (I'm referring to
the quotation marks, not the %i).

Nope.

The line Keith quotes contains two string literals, "%i" and " ",
separated by nothing but whitespace ("%i"" " or "%i" " " would be
equivalent). The compiler has (as it is required to) merged them into
a single string literal "%i " and it is this which printf() was
passed.
[snip]

Mark,

I was thinking that the conversion specifiers and string literals are always
separated by a comma,

printf("%i"," ");

Was what I was think and , was printed. That further confused me. My text is
an O'reilly pocket referecne simply called "C" and as O'reilly books are
there is an animal on the front promenantly a cow. Above is the code I kept
trying. The comma between the 2 string literals.

Bill
Jul 30 '08 #94
"Bill Cunningham" <no****@nspam.comwrites:
"Keith Thompson" <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
>Bill Cunningham: Do you have any comment on this? Do you know why
your X-Newsreader: header implies you're using Outlook Express, but
your Message-ID implies you're using trn?
Keith I don't think my headers are lying. I'm running old ver 6 of OE.
slrn didn't work out for me. All the newsreaders I've tried as late I
haven't been able to lock onto my news server with.
I don't use trn at all.
And the presence of "@trnddc06" in a Message-ID really doesn't imply
the use of trn at all.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jul 30 '08 #95
"Bill Cunningham" <no****@nspam.comwrites:
"Mark L Pappin" <ml*@acm.orgwrote in message
news:87************@Don-John.Messina...
>"Bill Cunningham" <no****@nspam.comwrites:
>>"Keith Thompson" <ks***@mib.orgwrote
A comment on your code. Why did you write

"%i" " "

? Do you understand exactly what that syntax means (I'm referring to
the quotation marks, not the %i).

Nope.

The line Keith quotes contains two string literals, "%i" and " ",
separated by nothing but whitespace ("%i"" " or "%i" " " would be
equivalent). The compiler has (as it is required to) merged them into
a single string literal "%i " and it is this which printf() was
passed.

[snip]

Mark,

I was thinking that the conversion specifiers and string literals are always
separated by a comma,

printf("%i"," ");

Was what I was think and , was printed. That further confused me. My text is
an O'reilly pocket referecne simply called "C" and as O'reilly books are
there is an animal on the front promenantly a cow. Above is the code I kept
trying. The comma between the 2 string literals.

Bill

The sherry is supposed to go in the trifle Bill, not down your gullet.

But 10 out of 10 for a wonderful stage act - it's bordering on the
beautiful at this stage. Listening to Santosh apologising to you had me
spilling my tea over some notes on my desk. You even managed to goad "Mr
Topic" Keith into discussing msgids and usenet posting headers!

LOL.

Classic stuff.

Jul 30 '08 #96
"Bill Cunningham" <no****@nspam.comwrites:
I was thinking that the conversion specifiers and string literals
are always separated by a comma,
printf("%i"," ");

Was what I was think
Format strings (which in turn contain conversion specifiers) usually
_are_ string literals.

Arguments to printf() beyond the first _must_ match their
corresponding conversion specifiers.

The specifier %i requires an int.
The specifier %s requires a string. (OK, fellow pedants - let's just
keep it simple for Bill at this time.)
and , was printed. That further confused me.
When you don't get what you expect, this should cause a light to come
on saying "Maybe I misunderstood, and need to figure out where I went
wrong". It shouldn't lead you to try removing a comma from the source
just because what you saw in the output included a comma.

At your present state of knowledge and apparent rate of acquisition,
DON'T just randomly try stuff. Post the complete program here along
with a precise description of what you expected and what you got,
along with any thoughts you might have about why.

mlp
Jul 30 '08 #97

"Mark L Pappin" <ml*@acm.orgwrote in message
news:87************@Don-John.Messina...
"Bill Cunningham" <no****@nspam.comwrites:
>I was thinking that the conversion specifiers and string literals
are always separated by a comma,
>printf("%i"," ");

Was what I was think

Format strings (which in turn contain conversion specifiers) usually
_are_ string literals.

Arguments to printf() beyond the first _must_ match their
corresponding conversion specifiers.

The specifier %i requires an int.
The specifier %s requires a string. (OK, fellow pedants - let's just
keep it simple for Bill at this time.)
>and , was printed. That further confused me.

When you don't get what you expect, this should cause a light to come
on saying "Maybe I misunderstood, and need to figure out where I went
wrong". It shouldn't lead you to try removing a comma from the source
just because what you saw in the output included a comma.

At your present state of knowledge and apparent rate of acquisition,
DON'T just randomly try stuff. Post the complete program here along
with a precise description of what you expected and what you got,
along with any thoughts you might have about why.

mlp
#include <stdio.h>

int
main (void)
{
int i;

for (i = 0; i < 7; i++)
{

printf ("%i\n", i);
}
}

I indented this program using indent. It looks more readable to others
than my usual indentaion. All this does is print vertically the number 0-7.
I have no idea how to even start working with the line numbers to obtain
exponenials.

Bill
Jul 30 '08 #98
"Bill Cunningham" <no****@nspam.comwrites:
#include <stdio.h>

int
main (void)
{
int i;

for (i = 0; i < 7; i++)
{

printf ("%i\n", i);
}
}
I indented this program using indent. It looks more readable to
others than my usual indentaion.
It'll do. Whatever options you used to run indent, keep using them.
All this does is print vertically the number 0-7. I have no idea
how to even start working with the line numbers to obtain
exponenials.
OK, that's fine. Let's recap what you know:

0. A C program consists of a sequence of statements which are executed
one after the other.
A;
B;
C;
will run first A, then B, then C. Blocks of such sequences, wrapped
in {}, can usually each be considered equivalent to a single
statement.

1. You can print the value of an int variable named i with
printf("%i", i);

2. You can print a space with
printf(" ");

3. You can print a newline with
printf("\n");

4. You can do some sequence of things once for each value of i between
0 and 7 inclusive with
for (i = 0; i < 7; i++) {
E;
F;
G;
}
Now, the new bits:
5. You can calculate a new value by writing an arithmetic expression
involving variables, so for example to get the value of i plus 3,
i + 3
or, to get the value of i multiplied by i
i * i

6. You don't have to store such a value anywhere explicitly - you can
use it almost anywhere you could use the name of a variable, and then
instead of the value of the variable being used you'll use the new
calculated value. For example, you can print the value of an i plus 3
with
printf("%i", i+3);
(compare this with (1) above). You _can_ store a calculated value if
you want but we'll worry about that later.
So: since the variable i holds the line number that the question asks
for, how could you calculate the square of the line number? How could
you print that new value? What about the cube?

If you think you can answer the 3 questions above, try modifying the
program you posted here to complete the answer to q4a.

mlp
Jul 31 '08 #99
Mark L Pappin <ml*@acm.orgwrites:
<snip>
4. You can do some sequence of things once for each value of i between
0 and 7 inclusive with
Nit-pick: 0 to 6 inclusive.
for (i = 0; i < 7; i++) {
E;
F;
G;
}
--
Ben.
Jul 31 '08 #100

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Canonical Latin | last post by:
"Leor Zolman" <leor@bdsoft.com> wrote > "Canonical Latin" <javaplus@hotmail.com> wrote: > > > ... > >But I'm still curious as to the rational of having type >...
21
by: Matteo Settenvini | last post by:
Ok, I'm quite a newbie, so this question may appear silly. I'm using g++ 3.3.x. I had been taught that an array isn't a lot different from a pointer (in fact you can use the pointer arithmetics to...
5
by: JezB | last post by:
What's the easiest way to concatenate arrays ? For example, I want a list of files that match one of 3 search patterns, so I need something like DirectoryInfo ld = new DirectoryInfo(searchDir);...
3
by: Michel Rouzic | last post by:
It's the first time I try using structs, and I'm getting confused with it and can't make it work properly I firstly define the structure by this : typedef struct { char *l1; int *l2; int Nval; }...
1
by: Rob Griffiths | last post by:
Can anyone explain to me the difference between an element type and a component type? In the java literature, arrays are said to have component types, whereas collections from the Collections...
41
by: Rene Nyffenegger | last post by:
Hello everyone. I am not fluent in JavaScript, so I might overlook the obvious. But in all other programming languages that I know and that have associative arrays, or hashes, the elements in...
6
by: Robert Bravery | last post by:
Hi all, Can some one show me how to achieve a cross product of arrays. So that if I had two arrays (could be any number) with three elements in each (once again could be any number) I would get:...
1
by: Doug_J_W | last post by:
I have a Visual Basic (2005) project that contains around twenty embedded text files as resources. The text files contain two columns of real numbers that are separated by tab deliminator, and are...
16
by: mike3 | last post by:
(I'm xposting this to both comp.lang.c++ and comp.os.ms- windows.programmer.win32 since there's Windows material in here as well as questions related to standard C++. Not sure how that'd go over...
29
weaknessforcats
by: weaknessforcats | last post by:
Arrays Revealed Introduction Arrays are the built-in containers of C and C++. This article assumes the reader has some experiece with arrays and array syntax but is not clear on a )exactly how...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.