PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.c > k&r2
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
k&r2

Réponse
 
LinkBack Outils de la discussion
Vieux 25/11/2007, 20h44   #1
Bill Cunningham
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut k&r2

I copied this code from page 9 k&r 2 and it gives an error that even I
can see. Celsius is uninialized.

/* code */

#include <stdio.h>

main(){
int fahr,celsius,lower,upper,step;
lower=0;
upper=300;
step=20;
fahr=lower;
while (fahr<=upper)
{celsius=5*(fahr-32)/9;
printf("%d\t%d\n",fahr,celsuis;
fahr=farh+step;}}

/*end*/

Celsius is intialized within the body of the while function. Why is this
code from k&r2 not working?

Bill


  Réponse avec citation
Vieux 25/11/2007, 20h48   #2
Walter Roberson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: k&r2

In article <b9l2j.29168$Xg.23657@trnddc06>,
Bill Cunningham <some@net.com> wrote:
> I copied this code from page 9 k&r 2 and it gives an error that even I
>can see. Celsius is uninialized.


>/* code */


>#include <stdio.h>
>
>main(){
> int fahr,celsius,lower,upper,step;
> lower=0;
> upper=300;
> step=20;
> fahr=lower;
> while (fahr<=upper)
> {celsius=5*(fahr-32)/9;
> printf("%d\t%d\n",fahr,celsuis;


Did you notice the misspelling of celsius on the above line?

> fahr=farh+step;}}
>
>/*end*/

--
"No one has the right to destroy another person's belief by
demanding empirical evidence." -- Ann Landers
  Réponse avec citation
Vieux 25/11/2007, 20h57   #3
Marco Manfredini
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: k&r2

Bill Cunningham wrote:
> I copied this code from page 9 k&r 2 and it gives an error that even I
> can see. Celsius is uninialized.
>
> /* code */
>
> #include <stdio.h>
>
> main(){
> int fahr,celsius,lower,upper,step;
> lower=0;
> upper=300;
> step=20;
> fahr=lower;
> while (fahr<=upper)
> {celsius=5*(fahr-32)/9;
> printf("%d\t%d\n",fahr,celsuis;
> fahr=farh+step;}}
>
> /*end*/
>
> Celsius is intialized within the body of the while function. Why is this
> code from k&r2 not working?


You should read the message again. Isn't it rather "celsuis is
undefined"? celsuis?

And did you get something about "farh"?

  Réponse avec citation
Vieux 25/11/2007, 21h13   #4
Bill Cunningham
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: k&r2


"Walter Roberson" <roberson@ibd.nrc-cnrc.gc.ca> wrote in message
news:ficn3p$4rh$1@canopus.cc.umanitoba.ca...
> In article <b9l2j.29168$Xg.23657@trnddc06>,
> Bill Cunningham <some@net.com> wrote:
>> I copied this code from page 9 k&r 2 and it gives an error that even I
>>can see. Celsius is uninialized.

>
>>/* code */

>
>>#include <stdio.h>
>>
>>main(){
>> int fahr,celsius,lower,upper,step;
>> lower=0;
>> upper=300;
>> step=20;
>> fahr=lower;
>> while (fahr<=upper)
>> {celsius=5*(fahr-32)/9;
>> printf("%d\t%d\n",fahr,celsuis;

>
> Did you notice the misspelling of celsius on the above line?


No. My mistake then.
>
>> fahr=farh+step;}}
>>
>>/*end*/



  Réponse avec citation
Vieux 25/11/2007, 22h27   #5
CBFalconer
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: k&r2

Bill Cunningham wrote:
>
> I copied this code from page 9 k&r 2 and it gives an error that
> even I can see. Celsius is uninialized.
>
> /* code */
>
> #include <stdio.h>
>
> main(){
> int fahr,celsius,lower,upper,step;
> lower=0;
> upper=300;
> step=20;
> fahr=lower;
> while (fahr<=upper)
> {celsius=5*(fahr-32)/9;
> printf("%d\t%d\n",fahr,celsuis;
> fahr=farh+step;}}
>
> /*end*/
>
> Celsius is intialized within the body of the while function. Why
> is this code from k&r2 not working?


Because that is not the code from K&R.

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
Try the download section.


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

  Réponse avec citation
Vieux 25/11/2007, 22h40   #6
J. J. Farrell
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: k&r2

Bill Cunningham wrote:
> I copied this code from page 9 k&r 2 and it gives an error that even I
> can see. Celsius is uninialized.
>
> /* code */
>
> #include <stdio.h>
>
> main(){
> int fahr,celsius,lower,upper,step;
> lower=0;
> upper=300;
> step=20;
> fahr=lower;
> while (fahr<=upper)
> {celsius=5*(fahr-32)/9;
> printf("%d\t%d\n",fahr,celsuis;
> fahr=farh+step;}}
>
> /*end*/
>
> Celsius is intialized within the body of the while function. Why is this
> code from k&r2 not working?


Most likely because of various typos which make it very different from
the code in K&R2.
  Réponse avec citation
Vieux 26/11/2007, 03h16   #7
Joe Wright
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: k&r2

Bill Cunningham wrote:
> I copied this code from page 9 k&r 2 and it gives an error that even I
> can see. Celsius is uninialized.
>
> /* code */
>
> #include <stdio.h>
>
> main(){
> int fahr,celsius,lower,upper,step;
> lower=0;
> upper=300;
> step=20;
> fahr=lower;
> while (fahr<=upper)
> {celsius=5*(fahr-32)/9;
> printf("%d\t%d\n",fahr,celsuis;
> fahr=farh+step;}}
>
> /*end*/
>
> Celsius is intialized within the body of the while function. Why is this
> code from k&r2 not working?
>
> Bill
>
>

Mine works..

#include <stdio.h>

int main(void)
{
int fahr, celcius;
int lower, upper, step;

lower = 0;
upper = 300;
step = 20;

fahr = lower;
while (fahr <= upper) {
celcius = 5 * (fahr - 32) / 9;
printf("%d\t%d\n", fahr, celcius);
fahr = fahr + step;
}
return 0;
}

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
  Réponse avec citation
Vieux 26/11/2007, 05h23   #8
TerryP
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: k&r2

Bill Cunningham wrote:

>>> {celsius=5*(fahr-32)/9;
>>> printf("%d\t%d\n",fahr,celsuis;

>>
>> Did you notice the misspelling of celsius on the above line?

>
> No. My mistake then.


The Typo, the bane of compilation!

I remember I once spent 2 hours trying to find the problem in a program (of
mine) that failed to build, some times I wish they made a compiler that gave
errors like:

file:line !!! PEBKAC !!!
sp,member != sp.member -- you are a blind idiot,

After finally finding out that I had been working to long to notice the
difference between , and . I decided to get a better font xD

--
no brainer:
A decision which, viewed through the retrospectoscope,
is "obvious" to those who failed to make it originally.
  Réponse avec citation
Vieux 26/11/2007, 05h50   #9
Martin Ambuhl
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: k&r2

Bill Cunningham wrote:
> I copied this code from page 9 k&r 2 and it gives an error that even I
> can see. Celsius is uninialized.

It has a value assigned before use, so what's the problem?
[...]
int fahr,celsius,lower,upper,step;
[...]
> while (fahr<=upper)
> {celsius=5*(fahr-32)/9;

[...]
> Why is this
> code from k&r2 not working?


Is this really the code from K&R2? If it is, perhaps we should retreat
to K&R1, where these lines are
while )fahr <= upper) {
celsius = (5.0/9.0) * (fahr-32.0);
  Réponse avec citation
Vieux 26/11/2007, 07h18   #10
Joachim Schmitz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: k&r2

"CBFalconer" <cbfalconer@yahoo.com> schrieb im Newsbeitrag
news:4749F6CE.B79E4735@yahoo.com...
> Bill Cunningham wrote:
>>
>> I copied this code from page 9 k&r 2 and it gives an error that
>> even I can see. Celsius is uninialized.
>>
>> /* code */
>>
>> #include <stdio.h>
>>
>> main(){
>> int fahr,celsius,lower,upper,step;
>> lower=0;
>> upper=300;
>> step=20;
>> fahr=lower;
>> while (fahr<=upper)
>> {celsius=5*(fahr-32)/9;
>> printf("%d\t%d\n",fahr,celsuis;
>> fahr=farh+step;}}
>>
>> /*end*/
>>
>> Celsius is intialized within the body of the while function. Why
>> is this code from k&r2 not working?

>
> Because that is not the code from K&R.

Very ful answer 8-(
Fortunatly others had been far more full in pointing out the typo(s)

Bye, Jojo


  Réponse avec citation
Vieux 26/11/2007, 07h35   #11
Joachim Schmitz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: k&r2

"Martin Ambuhl" <mambuhl@earthlink.net> schrieb im Newsbeitrag
news:5qv56aF11u6miU1@mid.individual.net...
> Bill Cunningham wrote:
>> I copied this code from page 9 k&r 2 and it gives an error that even
>> I can see. Celsius is uninialized.

> It has a value assigned before use, so what's the problem?
> [...]
> int fahr,celsius,lower,upper,step;
> [...]
>> while (fahr<=upper)
>> {celsius=5*(fahr-32)/9;

> [...]
>> Why is this code from k&r2 not working?

>
> Is this really the code from K&R2? If it is, perhaps we should retreat to
> K&R1, where these lines are
> while )fahr <= upper) {
> celsius = (5.0/9.0) * (fahr-32.0);

Really? Does K&R1 have such bad typos?

After correction it gives a warning:
implicit conversion from "double" to "int": rounding, sign extension, or
loss of accuracy may result

Bye, Jojo


  Réponse avec citation
Vieux 26/11/2007, 07h35   #12
Joachim Schmitz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: k&r2

"Joe Wright" <joewwright@comcast.net> schrieb im Newsbeitrag
news:27SdnaWFpZvgp9fanZ2dnUVZ_hudnZ2d@comcast.com. ..
> Bill Cunningham wrote:
>> I copied this code from page 9 k&r 2 and it gives an error that even
>> I can see. Celsius is uninialized.
>>
>> /* code */
>>
>> #include <stdio.h>
>>
>> main(){
>> int fahr,celsius,lower,upper,step;
>> lower=0;
>> upper=300;
>> step=20;
>> fahr=lower;
>> while (fahr<=upper)
>> {celsius=5*(fahr-32)/9;
>> printf("%d\t%d\n",fahr,celsuis;
>> fahr=farh+step;}}
>>
>> /*end*/
>>
>> Celsius is intialized within the body of the while function. Why is this
>> code from k&r2 not working?
>>
>> Bill
>>
>>

> Mine works..
>
> #include <stdio.h>
>
> int main(void)
> {
> int fahr, celcius;
> int lower, upper, step;
>
> lower = 0;
> upper = 300;
> step = 20;
>
> fahr = lower;
> while (fahr <= upper) {
> celcius = 5 * (fahr - 32) / 9;
> printf("%d\t%d\n", fahr, celcius);
> fahr = fahr + step;
> }
> return 0;
> }

Your code might work, but it too misspells celsius.

Bye, Jojo

PS: This is something I notice immediatelly, because Celsius(weg) is the
street I live at... If I have to spell Celsius I usually refer to
Fahrenheit, once with the result that it got spelled "Felsius" 8-)


  Réponse avec citation
Vieux 26/11/2007, 08h56   #13
Martin Ambuhl
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: k&r2

Joachim Schmitz wrote:
> "Martin Ambuhl" <mambuhl@earthlink.net> schrieb im Newsbeitrag
> news:5qv56aF11u6miU1@mid.individual.net...
>> Bill Cunningham wrote:
>>> I copied this code from page 9 k&r 2 and it gives an error that even
>>> I can see. Celsius is uninialized.

>> It has a value assigned before use, so what's the problem?
>> [...]
>> int fahr,celsius,lower,upper,step;
>> [...]
>>> while (fahr<=upper)
>>> {celsius=5*(fahr-32)/9;

>> [...]
>>> Why is this code from k&r2 not working?

>> Is this really the code from K&R2? If it is, perhaps we should retreat to
>> K&R1, where these lines are
>> while )fahr <= upper) {
>> celsius = (5.0/9.0) * (fahr-32.0);

> Really? Does K&R1 have such bad typos?


No, that's my typo (and unless I missing something, that is properly
singular).
>
> After correction it gives a warning:
> implicit conversion from "double" to "int": rounding, sign extension, or
> loss of accuracy may result


While your implementation is free to issue such warnings, they are
hardly required. People with a mania for compiles without warnings
might take this is an indication that they should "fix" the code with a
useless cast. Since casts to "shut the compiler up" are all too
frequently a bad idea, I'm not so sure that the warning is a good idea.
  Réponse avec citation
Vieux 26/11/2007, 09h09   #14
santosh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: k&r2

In article <fidsvi$1gj$1@online.de>, Joachim Schmitz
<nospam.jojo@schmitz-digital.de> wrote on Monday 26 Nov 2007 1:05 pm:

> "Martin Ambuhl" <mambuhl@earthlink.net> schrieb im Newsbeitrag
> news:5qv56aF11u6miU1@mid.individual.net...
>> Bill Cunningham wrote:
>>> I copied this code from page 9 k&r 2 and it gives an error that
>>> even
>>> I can see. Celsius is uninialized.

>> It has a value assigned before use, so what's the problem?
>> [...]
>> int fahr,celsius,lower,upper,step;
>> [...]
>>> while (fahr<=upper)
>>> {celsius=5*(fahr-32)/9;

>> [...]
>>> Why is this code from k&r2 not working?

>>
>> Is this really the code from K&R2? If it is, perhaps we should
>> retreat to K&R1, where these lines are
>> while )fahr <= upper) {
>> celsius = (5.0/9.0) * (fahr-32.0);

> Really? Does K&R1 have such bad typos?
>
> After correction it gives a warning:
> implicit conversion from "double" to "int": rounding, sign extension,
> or loss of accuracy may result


I could be wrong but, depending on the value in 'fahr', that statement
might invoke undefined behaviour.

  Réponse avec citation
Vieux 26/11/2007, 09h44   #15
Richard Heathfield
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: k&r2

Joachim Schmitz said:

> "Joe Wright" <joewwright@comcast.net> schrieb im Newsbeitrag


<snip>

>> printf("%d\t%d\n", fahr, celcius);
>> fahr = fahr + step;
>> }
>> return 0;
>> }

> Your code might work, but it too misspells celsius.
>
> Bye, Jojo
>
> PS: This is something I notice immediatelly,


I note that your spelling flame contains a spelling error. It's
heart-warming to see the old traditions being maintained. :-)

--
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
  Réponse avec citation
Vieux 26/11/2007, 10h01   #16
Joachim Schmitz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: k&r2

"Richard Heathfield" <rjh@see.sig.invalid> schrieb im Newsbeitrag
news:r5ednTvt4P9bCdfanZ2dnUVZ8vydnZ2d@bt.com...
> Joachim Schmitz said:
>
>> "Joe Wright" <joewwright@comcast.net> schrieb im Newsbeitrag

>
> <snip>
>
>>> printf("%d\t%d\n", fahr, celcius);
>>> fahr = fahr + step;
>>> }
>>> return 0;
>>> }

>> Your code might work, but it too misspells celsius.
>>
>> Bye, Jojo
>>
>> PS: This is something I notice immediatelly,

>
> I note that your spelling flame contains a spelling error. It's
> heart-warming to see the old traditions being maintained. :-)

After all I live at Celsiusweg, not at Immediately Drive 8-)

Bye, Jojo


  Réponse avec citation
Vieux 26/11/2007, 10h04   #17
Joachim Schmitz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: k&r2

"Martin Ambuhl" <mambuhl@earthlink.net> schrieb im Newsbeitrag
news:5qvg25F11d209U1@mid.individual.net...
> Joachim Schmitz wrote:
>> "Martin Ambuhl" <mambuhl@earthlink.net> schrieb im Newsbeitrag
>> news:5qv56aF11u6miU1@mid.individual.net...
>>> Bill Cunningham wrote:

snip
>> After correction it gives a warning:
>> implicit conversion from "double" to "int": rounding, sign extension, or
>> loss of accuracy may result

>
> While your implementation is free to issue such warnings, they are hardly
> required. People with a mania for compiles without warnings might take
> this is an indication that they should "fix" the code with a useless cast.
> Since casts to "shut the compiler up" are all too frequently a bad idea,
> I'm not so sure that the warning is a good idea.

But in this case it tells me that using double arithmetic doesn't buy a
thing in the first place.

Bye, Jojo


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 19h13.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,24361 seconds with 25 queries