473,385 Members | 1,890 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,385 software developers and data experts.

doubles and ints

Is this valid C syntax ?

double=double/int;

I seem to be having trouble here.

Bill
Jul 11 '08 #1
48 2483
On Jul 11, 10:36 am, "Bill Cunningham" <nos...@nspam.comwrote:
Is this valid C syntax ?

double=double/int;

I seem to be having trouble here.

Bill
So if there's a double d and an int i, you're asking whether d = d / i
is valid C syntax? I reckon that's right but if it doesn't get what
you want, go change it. Experiment till the stupid computer gives you
what you want. Convert i into a double and see what happens. Try

d = d / (double)i

Hope that works. Can't be screwed testing the code.
Jul 11 '08 #2
In article <7Wxdk.858$713.149@trnddc03>,
Bill Cunningham <no****@nspam.comwrote:
Is this valid C syntax ?
>double=double/int;
>I seem to be having trouble here.
No it is not.
$ cat foof.c
int main(void) {
double=double/int;
return 0;
}
$ cc -fullwarn foof.c
cc-1040 cc: ERROR File = foof.c, Line = 2
An identifier is expected.

double=double/int;
^

cc-1029 cc: ERROR File = foof.c, Line = 2
An expression is expected at this point.

double=double/int;
^

2 errors detected in the compilation of "foof.c".

'double' is a type name; when it appears at the beginning of
a statement, it is understood as being part of a variable declarator.
As you failed to follow the 'double' with a variable name (or
mix of qualifiers) before the '=', the syntax is invalid.

If you mean more generally is it valid to divide a variable or
value of type double by a variable or value of type int, and
assign the result to a variable of type double, then the answer is Yes,
that is syntactically and semantically permitted; the int would get
promoted to double and the expression would proceed from there.
--
"I will not approve any plan which is based on the old principle
of build now and repair later." -- Walter Hickle
Jul 11 '08 #3
On Jul 11, 11:06 am, rober...@ibd.nrc-cnrc.gc.ca (Walter Roberson)
wrote:
In article <7Wxdk.858$713.149@trnddc03>,

Bill Cunningham <nos...@nspam.comwrote:
Is this valid C syntax ?
double=double/int;
I seem to be having trouble here.

No it is not.

$ cat foof.c
int main(void) {
double=double/int;
return 0;}

$ cc -fullwarn foof.c
cc-1040 cc: ERROR File = foof.c, Line = 2
An identifier is expected.

double=double/int;
^

cc-1029 cc: ERROR File = foof.c, Line = 2
An expression is expected at this point.

double=double/int;
^

2 errors detected in the compilation of "foof.c".

'double' is a type name; when it appears at the beginning of
a statement, it is understood as being part of a variable declarator.
As you failed to follow the 'double' with a variable name (or
mix of qualifiers) before the '=', the syntax is invalid.

If you mean more generally is it valid to divide a variable or
value of type double by a variable or value of type int, and
assign the result to a variable of type double, then the answer is Yes,
that is syntactically and semantically permitted; the int would get
promoted to double and the expression would proceed from there.
--
"I will not approve any plan which is based on the old principle
of build now and repair later." -- Walter Hickle
Well then I don't see why he seems to be having trouble. The int is
implicitly being converted to a double and he doesn't like what he's
getting.
Jul 11 '08 #4
On Fri, 11 Jul 2008 00:36:19 GMT, "Bill Cunningham" <no****@nspam.com>
wrote:
Is this valid C syntax ?

double=double/int;

I seem to be having trouble here.
Post your compilable code so we can all see what the problem is.
Remove del for email
Jul 11 '08 #5

"Barry Schwarz" <sc******@dqel.comwrote in message
news:rv********************************@4ax.com...
On Fri, 11 Jul 2008 00:36:19 GMT, "Bill Cunningham" <no****@nspam.com>
wrote:
> Is this valid C syntax ?

double=double/int;

I seem to be having trouble here.

Post your compilable code so we can all see what the problem is.
Remove del for email
------
#include <stdio.h>
#include <stdlib.h>
#define _ex exit(EXIT_FAILURE)

int main (int argc,char *argv[]) {
if (argc!=2) {
puts("usage error");
_ex;
}
int count=1;
double x,y,z;

y=x;z=y/count; <-----

x=strtod(argv[1],NULL);
FILE *fp;
fp=fopen("s","a");
char *string="%.2f\t%.2f\t%.2f\t%i\n";
fprintf(fp,string,x,y,z,count);
fclose(fp);
return 0;
}
Jul 11 '08 #6

"Walter Roberson" <ro******@ibd.nrc-cnrc.gc.cawrote in message
news:g5**********@canopus.cc.umanitoba.ca...
In article <7Wxdk.858$713.149@trnddc03>,
Bill Cunningham <no****@nspam.comwrote:
> Is this valid C syntax ?
>>double=double/int;
>>I seem to be having trouble here.

No it is not.
[snip]

double a,b;
int c;
a=b/c;

That's what I mean.

Bill
Jul 11 '08 #7
On Jul 11, 12:04 pm, "Bill Cunningham" <nos...@nspam.comwrote:
"Barry Schwarz" <schwa...@dqel.comwrote in message

news:rv********************************@4ax.com... On Fri, 11 Jul 2008 00:36:19 GMT, "Bill Cunningham" <nos...@nspam.com>
wrote:
Is this valid C syntax ?
>double=double/int;
>I seem to be having trouble here.
Post your compilable code so we can all see what the problem is.
Remove del for email

------
#include <stdio.h>
#include <stdlib.h>
#define _ex exit(EXIT_FAILURE)

int main (int argc,char *argv[]) {
if (argc!=2) {
puts("usage error");
_ex;
}
int count=1;
double x,y,z;

y=x;z=y/count; <-----

x=strtod(argv[1],NULL);
FILE *fp;
fp=fopen("s","a");
char *string="%.2f\t%.2f\t%.2f\t%i\n";
fprintf(fp,string,x,y,z,count);
fclose(fp);
return 0;

}
Why do I get the feeling that argc != 2 wouldn't work?
You can't write y = x when the comp doesn't know the values stored in
y and x cos they're UNINITIALIZED. Ya gotta give them something before
you use them elsewhere. Which means that z=y/count doesn't work
either. And I hate people who write y=x instead of y = x.
Jul 11 '08 #8
"Bill Cunningham" <no****@nspam.comwrites:
"Barry Schwarz" <sc******@dqel.comwrote in message
news:rv********************************@4ax.com...
>On Fri, 11 Jul 2008 00:36:19 GMT, "Bill Cunningham" <no****@nspam.com>
wrote:
>> Is this valid C syntax ?

double=double/int;

I seem to be having trouble here.

Post your compilable code so we can all see what the problem is.
Remove del for email
------
#include <stdio.h>
#include <stdlib.h>
#define _ex exit(EXIT_FAILURE)

int main (int argc,char *argv[]) {
if (argc!=2) {
puts("usage error");
_ex;
}
int count=1;
double x,y,z;

y=x;z=y/count; <-----

x=strtod(argv[1],NULL);
FILE *fp;
fp=fopen("s","a");
char *string="%.2f\t%.2f\t%.2f\t%i\n";
fprintf(fp,string,x,y,z,count);
fclose(fp);
return 0;
}
When I compile the above, I get:

c.c:13: error: parse error before '<' token

When I remove the "<-----", it compiles without error. When I enable
more warnings, gcc complains about mixing declarations and statements
(allowed only in C99), and says:

c.c:11: warning: 'x' might be used uninitialized in this function

Looking at the code, x is not given an initial value. Whatever
garbage value it has is assigned to y, and then z is assigned y/1.

Style suggestions:

Add more whitespace, particularly around binary operators and after
commas. Drop the "_ex' macro and replace the single invocation of it
with a call to exit(EXIT_FAILURE) (identifiers starting with
underscores should be avoided, and the macro does nothing but make
your code more obscure anyway).

You initially posted a line of something that bore only an indirect
resemblance to your actual code, and told us only that you "seem to be
having some trouble". After considerable coaxing, you finally posted
some real code -- but you *still* haven't told us what the actual
problem is. I see no syntax errors in the code you posted (other than
the arrow, which I presume you added later). If there had been a
syntax error, your compiler would have reported it.

What is the actual problem you're having? Are you getting an error or
warning message from your compiler? If so, what *exactly* did it
print? Is the program misbehaving? If so, what *exactly* does it do,
and how does this differ from what you expected?

I won't ask this again.

--
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 11 '08 #9

"Keith Thompson" <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...

[snip]
What is the actual problem you're having? Are you getting an error or
warning message from your compiler? If so, what *exactly* did it
print? Is the program misbehaving? If so, what *exactly* does it do,
and how does this differ from what you expected?

I won't ask this again.
Everything compiles file. But when I input a number like 21.00 I get
this printed to a file.

21.00 0.00 0.00 1

That's not what I envisioned this to print but this at first.
21.00 21.00 21.00 1
Then I am going to probably add a do while loop.

Bill
Jul 11 '08 #10
"Bill Cunningham" <no****@nspam.comwrote in message
news:Dczdk.864$713.772@trnddc03...
>
"Barry Schwarz" <sc******@dqel.comwrote in message
news:rv********************************@4ax.com...
>On Fri, 11 Jul 2008 00:36:19 GMT, "Bill Cunningham" <no****@nspam.com>
wrote:
>> Is this valid C syntax ?

double=double/int;

I seem to be having trouble here.

Post your compilable code so we can all see what the problem is.
Remove del for email
------
#include <stdio.h>
#include <stdlib.h>
#define _ex exit(EXIT_FAILURE)

int main (int argc,char *argv[]) {
if (argc!=2) {
puts("usage error");
_ex;
}
int count=1;
double x,y,z;

y=x;z=y/count; <-----

x=strtod(argv[1],NULL);
FILE *fp;
fp=fopen("s","a");
char *string="%.2f\t%.2f\t%.2f\t%i\n";
fprintf(fp,string,x,y,z,count);
fclose(fp);
return 0;
}
Perhaps you meant something like this:

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

int main(int argc, char *argv[])
{
int count = 1;
double x = 1,
y,
z;
FILE *fp;

if (argc != 2) {
puts("usage error");
exit(EXIT_FAILURE);
}
y = x;
z = y / count;

x = strtod(argv[1], NULL);
fp = fopen("s", "a");
if (fp) {
fprintf(fp, "%.2f\t%.2f\t%.2f\t%i\n", x, y, z, count);
fclose(fp);
} else {
puts("failed to open file.");
}
return 0;
}
** Posted from http://www.teranews.com **
Jul 11 '08 #11
Bert <al*****************@gmail.comwrites:
On Jul 11, 12:04 pm, "Bill Cunningham" <nos...@nspam.comwrote:
<snip>
>int main (int argc,char *argv[]) {
if (argc!=2) {
puts("usage error");
_ex;
}
int count=1;
double x,y,z;

y=x;z=y/count; <-----

x=strtod(argv[1],NULL);
<snip>
Why do I get the feeling that argc != 2 wouldn't work?
I don't know. It seems to be one of more reasonable part of this
program.
You can't write y = x when the comp doesn't know the values stored in
y and x cos they're UNINITIALIZED.
That is overstating the problem. There is not problem with using y
uninitialised in this context.
Ya gotta give them something before
you use them elsewhere. Which means that z=y/count doesn't work
either. And I hate people who write y=x instead of y = x.
Try to limit yourself (especially on Usenet) to hating what people do
("I hate it when people write y=x") or the thing itself ("I hate y=x")
rather than hating people.

--
Ben.
Jul 11 '08 #12
On 11 Jul, 03:04, "Bill Cunningham" <nos...@nspam.comwrote:
"Barry Schwarz" <schwa...@dqel.comwrote in message
news:rv********************************@4ax.com... On Fri, 11 Jul 2008 00:36:19 GMT, "Bill Cunningham" <nos...@nspam.com>
wrote:
<snip>
>I seem to be having trouble here.
<snip>
------
#include <stdio.h>
#include <stdlib.h>
#define _ex exit(EXIT_FAILURE)
try to avoid starting identifiers with '_'. Only
The Implementor (the guy who writes the compiler and the
standard library) should use such identifiers.

Hiding things in macros makes your code obscure.
int main (int argc,char *argv[]) {
* * if (argc!=2) {
* * * *puts("usage error");
* * * *_ex;
* * * *}
* * int count=1;
* * double x,y,z;
you are mixing ststements with definitions which is not legal C89
(the most widely available standard).
* * y=x;z=y/count; * <-----
please use whitespace

y = x;
z = y / count;

x is an uninitialised variable. Hence x, y, and z
and indetereminate values. Why do you divide
by count which is equal to 1 (one)?
* * x=strtod(argv[1],NULL);
no error checking
* * FILE *fp;
* * fp=fopen("s","a");
no error checking
* * char *string="%.2f\t%.2f\t%.2f\t%i\n";
* * fprintf(fp,string,x,y,z,count);
x is equal to whatever strtod() returned
y and z are indeterminate.
* * fclose(fp);
* * return 0;

--
Nick Keighley
Jul 11 '08 #13
On 11 Jul, 04:07, "Bill Cunningham" <nos...@nspam.comwrote:
"Keith Thompson" <ks...@mib.orgwrote in message

news:ln************@nuthaus.mib.org...

[snip]
What is the actual problem you're having? *Are you getting an error or
warning message from your compiler? *If so, what *exactly* did it
print? *Is the program misbehaving? *If so, what *exactly* does it do,
and how does this differ from what you expected?
I won't ask this again.

* * Everything compiles file. But when I input a number like 21.00 I get
this printed to a file.

21.00 * *0.00 * *0.00 * *1

That's not what I envisioned this to print but this at first.

21.00 * *21.00 * *21.00 1

Then I am going to probably add a do while loop.
why?

--
Nick Keighley
Jul 11 '08 #14
In article <ln************@nuthaus.mib.org>,
Keith Thompson <ks***@mib.orgwrote:
....
>I won't ask this again.
Sure you will. Again and again. Until you die (or stop posting to clc,
which will probably occur that same day).

Jul 11 '08 #15
On Fri, 11 Jul 2008 03:07:47 GMT, "Bill Cunningham" <no****@nspam.com>
wrote:
>
"Keith Thompson" <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...

[snip]
>What is the actual problem you're having? Are you getting an error or
warning message from your compiler? If so, what *exactly* did it
print? Is the program misbehaving? If so, what *exactly* does it do,
and how does this differ from what you expected?

I won't ask this again.
Everything compiles file. But when I input a number like 21.00 I get
this printed to a file.

21.00 0.00 0.00 1

That's not what I envisioned this to print but this at first.
21.00 21.00 21.00 1
Then I am going to probably add a do while loop.
The only place you need to add a while loop is in your internal mental
process of haphazardly throwing code at a problem. Why a while loop?
Is there anything in your code you want to do more than once? If you
are just going to guess, you might as well compile your code with a
FORTRAN compiler. It will do the same amount of good.

You need to look at the code. When do you extract the argument from
the command line? When do you try to use this value? There should be
a very obvious chronological relationship between these two. One must
come before the other. Does your code comply with that relationship?
Remove del for email
Jul 12 '08 #16

"Dann Corbit" <dc*****@connx.comwrote in message
news:bc******************@news.teranews.com...
Perhaps you meant something like this:

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

int main(int argc, char *argv[])
{
int count = 1;
double x = 1,
y,
z;
FILE *fp;

if (argc != 2) {
puts("usage error");
exit(EXIT_FAILURE);
}
y = x;
z = y / count;

x = strtod(argv[1], NULL);
fp = fopen("s", "a");
if (fp) {
fprintf(fp, "%.2f\t%.2f\t%.2f\t%i\n", x, y, z, count);
fclose(fp);
} else {
puts("failed to open file.");
}
return 0;
}
Yes but I haven't added the error checking yet as you have yet. I'm not
finshed yet.

Bill
Jul 12 '08 #17
"Bill Cunningham" <no****@nspam.comwrote in message
news:jxTdk.33$kf4.29@trnddc03...
>
"Dann Corbit" <dc*****@connx.comwrote in message
news:bc******************@news.teranews.com...
>Perhaps you meant something like this:

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

int main(int argc, char *argv[])
{
int count = 1;
double x = 1,
y,
z;
FILE *fp;

if (argc != 2) {
puts("usage error");
exit(EXIT_FAILURE);
}
y = x;
z = y / count;

x = strtod(argv[1], NULL);
fp = fopen("s", "a");
if (fp) {
fprintf(fp, "%.2f\t%.2f\t%.2f\t%i\n", x, y, z, count);
fclose(fp);
} else {
puts("failed to open file.");
}
return 0;
}
Yes but I haven't added the error checking yet as you have yet. I'm not
finshed yet.
Neither was I. The above is not even close to a useful program yet, but it
did what I *guessed* that you wanted it to do without violation of the rules
of the C language. Your program was not a proper C program.
** Posted from http://www.teranews.com **
Jul 12 '08 #18

"Nick Keighley" <ni******************@hotmail.comwrote in message
news:f5**********************************@j22g2000 hsf.googlegroups.com...
On 11 Jul, 03:04, "Bill Cunningham" <nos...@nspam.comwrote:
"Barry Schwarz" <schwa...@dqel.comwrote in message
news:rv********************************@4ax.com... On Fri, 11 Jul 2008
00:36:19 GMT, "Bill Cunningham" <nos...@nspam.com>
wrote:
<snip>
>I seem to be having trouble here.
<snip>
------
#include <stdio.h>
#include <stdlib.h>
#define _ex exit(EXIT_FAILURE)
try to avoid starting identifiers with '_'. Only
The Implementor (the guy who writes the compiler and the
standard library) should use such identifiers.

Hiding things in macros makes your code obscure.
int main (int argc,char *argv[]) {
if (argc!=2) {
puts("usage error");
_ex;
}
int count=1;
double x,y,z;
you are mixing ststements with definitions which is not legal C89
(the most widely available standard).
y=x;z=y/count; <-----
please use whitespace

y = x;
z = y / count;

x is an uninitialised variable. Hence x, y, and z
and indetereminate values. Why do you divide
by count which is equal to 1 (one)?
x=strtod(argv[1],NULL);
no error checking
FILE *fp;
fp=fopen("s","a");
no error checking
char *string="%.2f\t%.2f\t%.2f\t%i\n";
fprintf(fp,string,x,y,z,count);
x is equal to whatever strtod() returned
y and z are indeterminate.
fclose(fp);
return 0;

OK. here's the output I want and what I want to do.

10.00 10.00 10.00 1
10.50 20.50 10.50 2
10.00 30.50 10.67 3

And so on.

Bill

Jul 12 '08 #19

"Dann Corbit" <dc*****@connx.comwrote in message
news:19******************@news.teranews.com...
Neither was I. The above is not even close to a useful program yet, but
it did what I *guessed* that you wanted it to do without violation of the
rules of the C language. Your program was not a proper C program.
The big thing I have missed out on is initializing the variables right?
I have only declared them accept for count.

Bill
Jul 12 '08 #20
"Bill Cunningham" <no****@nspam.comwrites:
"Dann Corbit" <dc*****@connx.comwrote in message
news:bc******************@news.teranews.com...
>Perhaps you meant something like this:

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

int main(int argc, char *argv[])
{
int count = 1;
double x = 1,
y,
z;
FILE *fp;

if (argc != 2) {
puts("usage error");
exit(EXIT_FAILURE);
}
y = x;
z = y / count;

x = strtod(argv[1], NULL);
fp = fopen("s", "a");
if (fp) {
fprintf(fp, "%.2f\t%.2f\t%.2f\t%i\n", x, y, z, count);
fclose(fp);
} else {
puts("failed to open file.");
}
return 0;
}
Yes but I haven't added the error checking yet as you have yet. I'm not
finshed yet.

Bill
LOL. Nice one Bill. The Regs will keep at it. You're their way out!

Jul 12 '08 #21

"Richard" <rg****@gmail.comwrote in message
news:g5**********@registered.motzarella.org...
LOL. Nice one Bill. The Regs will keep at it. You're their way out!
You might think this is funny Richard but I'm genuinely stuck. I
appreciate any help to but it goes so far and stops. How about you give me a
page number from k&r2 or something. I could work outta the hole from there.
They're right I'm throwing all the code I know at this thing and it's over
my head.

Bill
Jul 12 '08 #22
"Bill Cunningham" <no****@nspam.comwrites:
"Richard" <rg****@gmail.comwrote in message
news:g5**********@registered.motzarella.org...
>LOL. Nice one Bill. The Regs will keep at it. You're their way out!

You might think this is funny Richard but I'm genuinely stuck. I
appreciate any help to but it goes so far and stops. How about you give me a
page number from k&r2 or something. I could work outta the hole from there.
They're right I'm throwing all the code I know at this thing and it's over
my head.

Bill
How about you look it up yourself?

You clearly have no interest in reading or understanding any reply given
to you.

Jul 12 '08 #23
Bill Cunningham said:
I'm throwing all the code I know at this thing and
it's over my head.
That is where you are going wrong. If you throw code at a problem, it is a
sign that you do not understand the problem. Program constructs are not
fungible. You can't just keep piling up ifs and whiles and fors and ints
and doubles until critical mass is reached, any more than you can heap
bricks and windowframes and mortar and slates in a pile and expect them to
become a house.

Stop throwing, and start thinking.

--
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 12 '08 #24

"Richard" <rg****@gmail.comwrote in message
news:g5**********@registered.motzarella.org...

How about you look it up yourself?

You clearly have no interest in reading or understanding any reply given
to you.
I'm unclear on whether to use while or for. But that's my next step. Not
understanding something yes not being interested no. Why would I want to
learn something so bad if I had no interest in it. I pulled out k&r2 the
other day and sat down to proceed with chapter 1. Or dive into about 10 foot
of water with no life raft and no prior swimming lessons.
I can focus on k&r2 or try, and my difficulties with that has nothing to
do with anyone here on usenet. I can do the excersies and I'm willing to but
I can tell you this. There will be 2 or 3 different answers from me for
every question that has one answer. This is as frustrating to me as anyone
else.
Bill
Jul 12 '08 #25
In article <uo******************************@bt.com>,
Richard Heathfield <rj*@see.sig.invalidwrote:
Bill Cunningham said:
I'm throwing all the code I know at this thing and
it's over my head.

That is where you are going wrong. If you throw code at a problem, it is a
sign that you do not understand the problem. Program constructs are not
fungible. You can't just keep piling up ifs and whiles and fors and ints
and doubles until critical mass is reached, any more than you can heap
bricks and windowframes and mortar and slates in a pile and expect them to
become a house.

Stop throwing, and start thinking.
Synchronicity .... I was just about to make exactly this point.

It's tempting to suggest that the "pile up changes at random"
method might not be as hopeless as it seems -- isn't that sort of
what genetic algorithms do, very loosely speaking? and perhaps
there's also a comparison with the evolution of living things? --
but it doesn't seem like the most efficient method.

As I'm often tempted to tell students (in entry-level university
courses in programming), when they seem to be hoping that if they
type random changes fast enough something useful will happen ....:

Put down the keyboard. Take a deep breath. Think. *Then* you
may pick up the keyboard and type again.

--
B. L. Massingill
ObDisclaimer: I don't speak for my employers; they return the favor.
Jul 12 '08 #26
"Bill Cunningham" <no****@nspam.comwrites:
"Richard" <rg****@gmail.comwrote in message
news:g5**********@registered.motzarella.org...

>How about you look it up yourself?

You clearly have no interest in reading or understanding any reply given
to you.

I'm unclear on whether to use while or for. But that's my next
step. Not
Why? What IS IT YOU WANT TO DO? Maybe best just to choose ONE and then go
back and look at it later and decide if the OTHER makes it more readable
and maintainable.
understanding something yes not being interested no. Why would I want to
learn something so bad if I had no interest in it. I pulled out k&r2
the
Don't be such a dumb arse. You are learning a computer language. How do
you KNOW you do not need something unless you first learn what it is.
other day and sat down to proceed with chapter 1. Or dive into about 10 foot
of water with no life raft and no prior swimming lessons.
Huh? K&R2 has a tutorial.
I can focus on k&r2 or try, and my difficulties with that has nothing to
do with anyone here on usenet. I can do the excersies and I'm willing to but
I can tell you this. There will be 2 or 3 different answers from me for
every question that has one answer. This is as frustrating to me as anyone
else.
So stop being so dim and work it yourself and when you have a real
question then post it.
>

Bill
Jul 12 '08 #27
Hello Bill, List

On Jul 12, 4:51 pm, "Bill Cunningham" <nos...@nspam.comwrote:

Bill

If I can give you one advice, it will be: try another language before
C. C pull you too much to the edge. You need to do everything by hand,
and for you, as we can see, that is too hard to glark. Your problem
isn't really the C syntax, but transform problem in algorithm. Sorry
to say that, but your code doesn't make sense to me, and will probably
make no sense to others. Try some other language to learn how to do
that, and then move to C. Some here start working with C because they
have no options (but I don't think they get wedged as you are,
usually).

Loop through that links should be a nice start to you. Read and
understand them will (help to) avoid your while(1){nailing jelly to a
tree;}, and some day make your program's less dependent of the phase
of the moon:

http://en.wikipedia.org/wiki/Computer_Programming
http://en.wikipedia.org/wiki/Programming_language
http://en.wikipedia.org/wiki/Algorithm
http://en.wikipedia.org/wiki/Procedural_programming
http://en.wikipedia.org/wiki/Logic
http://en.wikipedia.org/wiki/Binary_numeral_system

Regards
Rafael
Jul 13 '08 #28

"Richard Heathfield" <rj*@see.sig.invalidwrote in message
news:uo******************************@bt.com...
Stop throwing, and start thinking.
I don't unfortunately know a whole lot eithier. Maybe that's why my
throwing runs out quick.

Bill

Jul 13 '08 #29

"soscpd" <so****@gmail.comwrote in message
news:93**********************************@m44g2000 hsc.googlegroups.com...
Hello Bill, List

On Jul 12, 4:51 pm, "Bill Cunningham" <nos...@nspam.comwrote:

Bill

If I can give you one advice, it will be: try another language before
C. C pull you too much to the edge. You need to do everything by hand,
and for you, as we can see, that is too hard to glark. Your problem
isn't really the C syntax, but transform problem in algorithm. Sorry
to say that, but your code doesn't make sense to me, and will probably
make no sense to others. Try some other language to learn how to do
that, and then move to C.
[snip]

I learned Basic many years ago. It was a piece of cake. Algorithms I know
nothing about. Basic itself wasn't a problems but putting things where they
needed to go was a bit.

Bill
Jul 13 '08 #30
On 12 Jul, 20:16, "Bill Cunningham" <nos...@nspam.comwrote:
"Richard" <rgr...@gmail.comwrote in message
news:g5**********@registered.motzarella.org...
LOL. Nice one Bill. The Regs will keep at it. You're their way out!

* * You might think this is funny Richard but I'm genuinely stuck. I
appreciate any help to but it goes so far and stops. How about you give me a
page number from k&r2 or something. I could work outta the hole from there.
They're right I'm throwing all the code I know at this thing and it's over
my head.
WHAT ARE YOU TRYING TO DO
Jul 14 '08 #31
On 12 Jul, 02:24, "Bill Cunningham" <nos...@nspam.comwrote:
"Nick Keighley" <nick_keighley_nos...@hotmail.comwrote in message

news:f5**********************************@j22g2000 hsf.googlegroups.com...
On 11 Jul, 03:04, "Bill Cunningham" <nos...@nspam.comwrote:
"Barry Schwarz" <schwa...@dqel.comwrote in message
news:rv********************************@4ax.com... On Fri, 11 Jul 2008
00:36:19 GMT, "Bill Cunningham" <nos...@nspam.com>
wrote:

<snip>
>>I seem to be having trouble here.

<snip>
------
#include <stdio.h>
#include <stdlib.h>
#define _ex exit(EXIT_FAILURE)

try to avoid starting identifiers with '_'. Only
The Implementor (the guy who writes the compiler and the
standard library) should use such identifiers.

Hiding things in macros makes your code obscure.
int main (int argc,char *argv[]) {
if (argc!=2) {
puts("usage error");
_ex;
}
int count=1;
double x,y,z;

you are mixing ststements with definitions which is not legal C89
(the most widely available standard).
y=x;z=y/count; <-----

please use whitespace

* * *y = x;
* * *z = y / count;

x is an uninitialised variable. Hence x, y, and z
and indetereminate values. Why do you divide
by count which is equal to 1 (one)?
x=strtod(argv[1],NULL);

no error checking
FILE *fp;
fp=fopen("s","a");

no error checking
char *string="%.2f\t%.2f\t%.2f\t%i\n";
fprintf(fp,string,x,y,z,count);

x is equal to whatever strtod() returned
y and z are indeterminate.
fclose(fp);
return 0;

OK. here's the output I want and what I want to do.

10.00 * *10.00 * *10.00 * *1
10.50 * *20.50 * *10.50 * *2
10.00 * *30.50 * * 10.67 * *3

And so on.
I know nothing about the financial world (which I'm guessing
from previous posts is your application domain) so this
might as well be a series of random numbers.

What is your input and how is input derived from output?

In pseudo code you want somthing like this

LOOP UNTIL finished
read input
calc value
print output
END LOOP
--
Nick Keighley

Felix Bloch as a young man once told Heisenberg that
"space is a field of linear operators". "Nonsense" replied Heisenberg,
"space is blue and birds fly through it".
Jul 14 '08 #32

"Nick Keighley" <ni******************@hotmail.comwrote in message
news:6d**********************************@m44g2000 hsc.googlegroups.com...

I know nothing about the financial world (which I'm guessing
from previous posts is your application domain) so this
might as well be a series of random numbers.

What is your input and how is input derived from output?

In pseudo code you want somthing like this

LOOP UNTIL finished
read input
calc value
print output
END LOOP
Nick The above looks exactly like what I want but I really don't think
I've gotten that far. I am working to create a mean of numbers. Calculated
from each input. I want 3 rows of doubles separated by tabs. Then in a final
column to the right a row of ints. These ints are what I am going to divide
my last row of doubles with. I can separate these into functions and call
them from main or whatever is simplest. On another note, is strtod and atof
about the same function ? Or should I say do they do about the same thing?

Bill
Jul 14 '08 #33
Bill, could you persuade your news reader to quote correctly?
You also snip very heavily.

On 14 Jul, 22:39, "Bill Cunningham" <nos...@nspam.comwrote:
"Nick Keighley" <nick_keighley_nos...@hotmail.comwrote in message
news:6d**********************************@m44g2000 hsc.googlegroups.com...
Nick Keighley here:
I know nothing about the financial world (which I'm guessing
from previous posts is your application domain) so this
might as well be a series of random numbers.

What is your input and how is input derived from output?

In pseudo code you want somthing like this

* * LOOP UNTIL finished
* * * * *read input
* * * * *calc value
* * * * *print output
* * END LOOP
To be honest from your code at the beginning of the thread
and your sample output I can deduce what you are trying to do.
I could write the program for you. But I don't think that would help
you. One skill that is essential to programming is the ability
to express yourself clearly. You don't have it. If you can't
explain what you want to do how can you expect to write a program
to do it?

In your original code did you notice that you performed a calculation
using x BEFORE YOU HAD READ A VALUE INTO x?

You need to call strtod() BEFORE you calculate y.

Bill: from here
* * Nick The above looks exactly like what I want but I really don't think
I've gotten that far. I am working to create a mean of numbers.
what numbers? Do you read them from a file? You can't calculate a mean
without a loop!

double mean (double a[], int n)
{
double sum;

for (i = 0; i < n; i++)
sum += a[i];

return sum / n;
}

So is y supposed to be the sum in your program?

Calculated from each input.
you can't calculate a mean "from each input"

I want 3 rows of doubles separated by tabs.
don't tell me the format! Tell me what the doubles *mean*
Then in a final
column to the right a row of ints. These ints are what I am going to divide
my last row of doubles with.
why? I thought I understood what you were doing but no longer!
I can separate these into functions and call
them from main or whatever is simplest.
STEP 1. DECIDE WHAT YOU WANT TO DO!!!!!!!!!!!!

what is the value in the first column (I guess the input-
from a file?). What is column 2 (the sum of numbers so far?)
and column 3 (the mean so far?)

why can't you say!!

On another note, is strtod and atof
about the same function ?
roughly. strtod() handles errors better. atof() returns
0.0 on error. atof("BAD WOLF") returns 0.0, which may not
be what you want.
Or should I say do they do about the same thing?
well since you don't do error checking they are
pretty much identical. This is a suggestion to
do some error checking.

1. decide what you want to do
2. write it down on a peice of paper
3. write pseudo code (like mine above)
4. desk check it- run it in your head
as if you were the computer
5. if it seems ok, translate the p-code
to C
6. test it

this may seem dull and boring but your way of
just throwing random program structures at a
non-specific reuirement doesn't yield working
programs.
--
Nick Keighley

Every sentence I utter must be understood not as an affirmation,
but as a question.
Niels Bohr
Jul 15 '08 #34
On 15 Jul, 10:15, Nick Keighley <nick_keighley_nos...@hotmail.com>
wrote:
double mean (double a[], int n)
{
* *double sum;
oops!

double sum = 0.0;
>
* *for (i = 0; i < n; i++)
* * * *sum += a[i];

* *return sum / n;

}
--
Nick Keighley
Jul 15 '08 #35

"Nick Keighley" <ni******************@hotmail.comwrote in message
news:73**********************************@k13g2000 hse.googlegroups.com...
Bill, could you persuade your news reader to quote correctly?
You also snip very heavily.

On 14 Jul, 22:39, "Bill Cunningham" <nos...@nspam.comwrote:
"Nick Keighley" <nick_keighley_nos...@hotmail.comwrote in message
news:6d**********************************@m44g2000 hsc.googlegroups.com...
Nick Keighley here:
I know nothing about the financial world (which I'm guessing
from previous posts is your application domain) so this
might as well be a series of random numbers.

What is your input and how is input derived from output?

In pseudo code you want somthing like this

LOOP UNTIL finished
read input
calc value
print output
END LOOP
To be honest from your code at the beginning of the thread
and your sample output I can deduce what you are trying to do.
I could write the program for you. But I don't think that would help
you. One skill that is essential to programming is the ability
to express yourself clearly. You don't have it. If you can't
explain what you want to do how can you expect to write a program
to do it?

In your original code did you notice that you performed a calculation
using x BEFORE YOU HAD READ A VALUE INTO x?

You need to call strtod() BEFORE you calculate y.

Bill: from here
Nick The above looks exactly like what I want but I really don't think
I've gotten that far. I am working to create a mean of numbers.
what numbers? Do you read them from a file? You can't calculate a mean
without a loop!

double mean (double a[], int n)
{
double sum;

for (i = 0; i < n; i++)
sum += a[i];

return sum / n;
}

So is y supposed to be the sum in your program?
Yes. Yes. Exactly, z is supposed to be the actual average of the y
divided by count. I have been thinking while loops and perhaps all this time
I've been needing for loops. Maybe nested for loops.

Bill
Jul 15 '08 #36
"Bill Cunningham" <no****@nspam.comwrites:
[Improperly marked quoted materal snipped]
Yes. Yes. Exactly, z is supposed to be the actual average of the y
divided by count. I have been thinking while loops and perhaps all this time
I've been needing for loops. Maybe nested for loops.
Bill, most of the time you manage to post correct, but every now and
then you post a followup where the quoted material isn't marked.
*Please* spend some time figuring out what you're doing differently.
Whatever you did this time, please don't do it again.

I'm guessing that only the last paragraph above is yours, but I can't
be sure.

I think part of your trouble, as numerous people have told you, is
that you throw random language features at a problem with
understanding what you're doing.

Imagine a carpenter saying, "I've been thinking about using a hammer,
but maybe I need a screwdriver. Say, how about a Phillips screwdriver.
Or a bandsaw!". The carpenter needs to understand what he's building
*before* he can determine which tools to use.

I think you're doing something similar.

--
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 15 '08 #37
Keith Thompson <ks***@mib.orgwrites:
[...]
Bill, most of the time you manage to post correct, but every now and
[...]

s/correct/correctly/

(*sigh*)

--
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 15 '08 #38
"Bill Cunningham" <no****@nspam.comwrites:
<snip stuff I can't accurately quote>
... I have been thinking while loops and perhaps all this time
I've been needing for loops.
This does not make sense in C. The relation ship between a for loop
an a while is so close that you can always use either. The choice is
partly a matter of style, and partly what you want to emphasise to
readers of you code: A while loop stresses the condition for
continuing, a for loop draws attention to the initial action and the
change made at each step.

But the bottom line is: if you need a for, you can use a while and
vice-versa.
Maybe nested for loops.
Now the *structure* of loops and conditionals *does* reflect what a
program is really doing. In this case you won't need any nested
loops.

As far as I can tell you want:

double total = 0;
int data_count = 0;
double data_point;
while (fscanf(infile, "%lf", &data_point) == 1) {
total += data_point;
data_count += 1;
fprintf(outfile, "%7.3f %7.3f %7.3f %7d\n",
data_point, total, total/data_count, data_count);
}

--
Ben.
Jul 15 '08 #39
your posting is totally screwed. Skip to the end of the post
and look for <START HERE>
On 15 Jul, 20:22, "Bill Cunningham" <nos...@nspam.comwrote:
"Nick Keighley" <nick_keighley_nos...@hotmail.comwrote in message

news:73**********************************@k13g2000 hse.googlegroups.com...
Bill, could you persuade your news reader to quote correctly?
You also snip very heavily.

On 14 Jul, 22:39, "Bill Cunningham" <nos...@nspam.comwrote:
"Nick Keighley" <nick_keighley_nos...@hotmail.comwrote in message
news:6d**********************************@m44g2000 hsc.googlegroups.com....

Nick Keighley here:
I know nothing about the financial world (which I'm guessing
from previous posts is your application domain) so this
might as well be a series of random numbers.
What is your input and how is input derived from output?
In pseudo code you want somthing like this
LOOP UNTIL finished
read input
calc value
print output
END LOOP

To be honest from your code at the beginning of the thread
and your sample output I can deduce what you are trying to do.
I could write the program for you. But I don't think that would help
you. One skill that is essential to programming is the ability
to express yourself clearly. You don't have it. If you can't
explain what you want to do how can you expect to write a program
to do it?

In your original code did you notice that you performed a calculation
using x BEFORE YOU HAD READ A VALUE INTO x?

You need to call strtod() BEFORE you calculate y.

Bill: from here
Nick The above looks exactly like what I want but I really don't think
I've gotten that far. I am working to create a mean of numbers.

what numbers? Do you read them from a file? You can't calculate a mean
without a loop!

double mean (double a[], int n)
{
* *double sum;

* *for (i = 0; i < n; i++)
* * * *sum += a[i];

* *return sum / n;

}

So is y supposed to be the sum in your program?

* * Yes. Yes. Exactly, z is supposed to be the actual average of the y
divided by count. I have been thinking while loops and perhaps all this time
I've been needing for loops. Maybe nested for loops.
<START HERE>

you see you can do it!

so for each line in the file you want to print
<value<sum so far<mean so far<count>

pretty easy huh?

Well since you want to do something FOR EACH line you obviously
need a loop (or two?). Since you do the same thing for each
line I think you can see you only need one loop. The trick to
deciding what sort of loop you want is to think about when the
loop finishes. Are you looping for a fixed count? No you
don't know how big the file is until you read it. Are you
looping until a particular value occurs? Well you could but
it limits the program. Are you looping until you get to the
end of the file? Yes!

So we need to loop until the end of the file is reached.
This suggests

WHILE NOT END-OF-FILE
read number
print line
END

which probably corresponds to a C while-loop

Since the file is just numbers (I assume) you need to
look at fscanf(). Look it up. How do you know when
you've reached the end of the file? Use a while loop.

If you read your past posts (and the replies) I think
you'll find I've told you how to do this before.
--
Nick Keighley

"At terrestrial temeratures matter has complex properties
*which are likely to prove most difficult to unravel;
*but it is reasonable to hope that in a not too distant future
*we shall be competent to understand so simple thing as a star.
* Aurthur S. Eddington *"The Internal Constitution of Stars"
Jul 16 '08 #40

"Keith Thompson" <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
Bill, most of the time you manage to post correct, but every now and
then you post a followup where the quoted material isn't marked.
*Please* spend some time figuring out what you're doing differently.
Whatever you did this time, please don't do it again.

I'm guessing that only the last paragraph above is yours, but I can't
be sure.
Using OE and I have to do all manually.

Bill
Jul 17 '08 #41
Bill Cunningham wrote:
"Keith Thompson" <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
>Bill, most of the time you manage to post correct, but every now and
then you post a followup where the quoted material isn't marked.
*Please* spend some time figuring out what you're doing differently.
Whatever you did this time, please don't do it again.

I'm guessing that only the last paragraph above is yours, but I can't
be sure.

Using OE and I have to do all manually.
Try out OE-QuoteFix (Google will tell you were to get it)

Bye, Jojo
Jul 17 '08 #42
On Jul 13, 1:57*pm, "Bill Cunningham" <nos...@nspam.comwrote:
"soscpd" <sos...@gmail.comwrote in message

news:93**********************************@m44g2000 hsc.googlegroups.com...
Hello Bill, List
On Jul 12, 4:51 pm, "Bill Cunningham" <nos...@nspam.comwrote:
Bill
If I can give you one advice, it will be: try another language before
C. C pull you too much to the edge. You need to do everything by hand,
and for you, as we can see, that is too hard to glark. Your problem
isn't really the C syntax, but transform problem in algorithm. Sorry
to say that, but your code doesn't make sense to me, and will probably
make no sense to others. Try some other language to learn how to do
that, and then move to C.

[snip]

I learned Basic many years ago. It was a piece of cake. Algorithms I know
nothing about. Basic itself wasn't a problems but putting things where they
needed to go was a bit.
There I see a problem. Basic is a decent programming language for
middle school, but C is a very different language -- you can hardly
apply BASIC programming paradigms (goto is a classic example) to C and
get away with it on clc.

If you're in the mood to try harder: start with assembler, then move
to C. Trust me, things will make a lot more sense.
Jul 17 '08 #43

"Joachim Schmitz" <no*********@schmitz-digital.dewrote in message
news:g5**********@online.de...
>Try out OE-QuoteFix (Google will tell you were to get it)

Bye, Jojo
I'm using it now since I found it. Is this more like it? It seems I have
to do things manually here too.

Bill
Jul 17 '08 #44
Joachim Schmitz wrote:
Bill Cunningham wrote:
> Using OE and I have to do all manually.

Try out OE-QuoteFix (Google will tell you were to get it)

Bye, Jojo
Ok now it's on I think.
Jul 17 '08 #45
Bill Cunningham wrote:
Joachim Schmitz wrote:
>Bill Cunningham wrote:
>> Using OE and I have to do all manually.

Try out OE-QuoteFix (Google will tell you were to get it)

Bye, Jojo

Ok now it's on I think.
Looks fine to me
Jul 18 '08 #46
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Bill Cunningham wrote:
Is this valid C syntax ?

double=double/int;

I seem to be having trouble here.

Bill

The short answer is "no". However, I think you mean to ask about:

double b=1;
int c=2;
double a=b/c;

If that is what you meant, you should try to post things that won't
elicit such responses as above. It is indeed valid; division involving
at least one floating point type (float, double, long, long long, etc.)
will have a result of the larger of double or the largest type involved
(so it will never return a float, for instance).

That said, you could assign the value to an int validly, thus rounding
the value down. Also, you could divide two int values such as 2/5, and
the result would be 0 (not 0.4) regardless of whether you assigned it to
an integer or floating point type.

If you didn't already know that, please look up type promotion and demotion.

- --
- --Falcon Darkstar Kirtaran
- --
- --OpenPGP: (7902:4457) 9282:A431

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQIcBAEBAgAGBQJIjmtoAAoJEKmxP9YxEE4r5JsP/3U+4KGSQtL8H4vNhDISFclo
bFgkL0xA1AR/xP8u8j6wAckBLIaWXupreBjGc/54ELzn2smAveYfhZTYMuUFYq4X
tjOXkzRiPCkP7yd3XZKSkl44Y04w3rPUw+xtWNbEIPmj0Gzsnb SLokfdF8UZEs8N
KBT33A1tliGJvsIDm2+qnuumd3JQfKfdkkpLCB+P5g0CBuQx4r 8px6rWhG4l2VbV
IPsxV1+wScku3DsEedipfUQix2Ky849xnLToxTAJxOl1Kb7r6+ 7X1qJymwb8G5AB
cnViBHH+pNTeE4ZD09BPv8qgCeMun5rR8zMVw5D+my+MHk+ZbO ajWbvYtK1XOLdS
Yqp5e+nwi3uoOVmpYhN2CV2hGGz79Nh/c+NQLssAHzpfHke8vgs9GIjpWBBuwRD5
PpRdQGiCsBwYj9VF/2DdcrJugE5iLPRryR4+rtO26bF2Zws8R1Rt4HuUC1wHjZYU
2DGedMEOkEuvD4yO6d/SDqvpIAy/MFQ46fdw4aOuju/rz7dKErKyeyuRR69mazvz
iF8A1KFl3F9kDJiycJYGDz4XcyQk6DBi9Sx1RPdakHfW044yXi OpSX4AGY+mokWA
TbdvyWC+LFOv3Kbdb87zSzEcxO4ajD6qnpHn8kXQIOMe2yYLGz +bGjQMmxjryTat
CKDzG32JMTyJe1cmpffX
=050B
-----END PGP SIGNATURE-----
Jul 29 '08 #47
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Bill Cunningham wrote:
"Walter Roberson" <ro******@ibd.nrc-cnrc.gc.cawrote in message
news:g5**********@canopus.cc.umanitoba.ca...
>In article <7Wxdk.858$713.149@trnddc03>,
Bill Cunningham <no****@nspam.comwrote:
>> Is this valid C syntax ?
double=double/int;
I seem to be having trouble here.
No it is not.
[snip]

double a,b;
int c;
a=b/c;

That's what I mean.

Bill

It is valid syntax, but the values of a, b, and c are all undefined
because you did not initialize them. However, no precision was lost.

- --
- --Falcon Darkstar Kirtaran
- --
- --OpenPGP: (7902:4457) 9282:A431

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQIcBAEBAgAGBQJIjmxKAAoJEKmxP9YxEE4r+oQQALNdgzDCMo Lggffki20TK/Cs
Rcypg1kfLeO4FgL0HBS5+zPm/LGK66tD3UjDcnHygJgdfCBrOdr7PRZ5miTFfyaE
dwD3leGaDqWWREY7ytnQhLhCq+osTnLGaoMnOhVhKAXgLDNomS Wht2MO+I+I891l
1TrRB5N0JJ6zx+ED1mfK7CX9i07bd3lLI5zL9G2roetKHyGM3M kelo7A6t+EKhyn
d146XGOk44KUsY26mCP7ZOUUCd3qh2QIe9S/t7jskQYoTvqWABA/M2aQSoJOt/UK
3tvyCVAU3WjLlS25unJIDx51SFXt6Mob8R56MNnZweZjZesjtX p4DdIBR2q+xMz3
DGzrVzBtkoW1/g2gDdw3gg/6/SzlF2qiaVP8JNwh6Wbq75OXloBMNvZHhVRzLdyM
w0x+lIGkfreTgQNSU4sH6p4ungQKcAdvMupCAbjH/ZyMz+giMg2dZq7AS981syHu
QQTxmiioqvLM5+24O0B4/Zhk2MM6Zvvlzg9CNe8NVwcIMCo9HbKVS0bzLTMUE/+l
USb/8bWPT0TVO228MVIUUl8Vh+11XuR+aYD6RkVjcUrc4kKMFAimG5/ZT+KQ9h4g
QCwplxdKfN5Xhp5RuKtxdhiTjsf9yZBFVRSjPZvW3uT/DJ4OpBnY/kmgq2YD/9Wr
LFzwzMX2Kcd85Y2Jvx+A
=ApH+
-----END PGP SIGNATURE-----
Jul 29 '08 #48
In article <d5**********************************@j1g2000prb.g ooglegroups.com>,
Old Wolf <ol*****@inspire.net.nzwrote:
On 13 Jul, 08:45, blm...@myrealbox.com <blm...@myrealbox.comwrote:
<badc0...@gmail.comwrote:
Bill Cunningham wrote:
y=x;z=y/count; <-----
x=strtod(argv[1],NULL);
[ snip ]
I seem to remember reading somewhere, probably in a discussion
of teaching beginning programming, that some beginners mentally
associate the assignment operator with the mathematical notion
of equality [1], and think that once one has written "y=x",
changes in x will propagate to y, which doesn't happen [2].
Could this be the problem here?

There are actually languages where writing 'y=x'
means that 'y' always has the value that 'x' does.
C is not one of those languages. (Those languages
are usually called 'functional' ones).
Good catch. I wasn't thinking about languages outside the
procedural/OO paradigm, but perhaps I should have been.
Assuming
the original poster isn't a troll, then this could
very well be his mental process.
--
B. L. Massingill
ObDisclaimer: I don't speak for my employers; they return the favor.
Jul 29 '08 #49

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

Similar topics

7
by: jdog1016 | last post by:
Recently I coded something for a class that uses a LOT of doubles with precision out to the thousands place. I did most of the arithmetic by multiplying each by a thousand and converting to an...
3
by: Chris N. Hinds | last post by:
I have a question regarding accessing long long ints in unions. I have constructed a union with a double, two ints in a structure, and a long long int. When the double is loaded with a...
25
by: Allan Rydberg | last post by:
hi i'm trying to shift a double, but i'm getting the error message '>>' illegal, left operand double. althought that the manpages say, '>>' and '<<' can be applied for int's only, i was able...
8
by: Dan | last post by:
Hi, I did a test in C# double x1 = 1.0; double x2 = 5.29980882362664E-315; int h1 = x1.GetHashCode(); int h2 = x2.GetHashCode(); It turned out that both h1 and h2 = 1072693248
5
by: Tales Normando | last post by:
The title says it all. Anyone?
10
by: Neville Lang | last post by:
Hi all, Here is a problem I first struck a while back in the Compact Framework. I am now using the full Framework (v2.0) and wanted to know whether there is anyway around this issue without...
12
by: John Smith | last post by:
This code for the comparison of fp types is taken from the C FAQ. Any problems using it in a macro? /* compare 2 doubles for equality */ #define DBL_ISEQUAL(a,b)...
6
by: Pavel | last post by:
Hello, Does anyone know a (preferably open-source) multi-platform C or C++ library that would be able to write and read C/C++ doubles and floats to/from streambuf, char array or similar device...
3
by: jerry.teshirogi | last post by:
I have the following class and main: ////////////////////////////////////////////////////////// #include <iostream.h> class myVector { public: double x, y, z:
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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.