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

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
Nov 25 '07 #1
16 1893
In article <b9l2j.29168$Xg.23657@trnddc06>,
Bill Cunningham <so**@net.comwrote:
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
Nov 25 '07 #2
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"?

Nov 25 '07 #3

"Walter Roberson" <ro******@ibd.nrc-cnrc.gc.cawrote in message
news:fi**********@canopus.cc.umanitoba.ca...
In article <b9l2j.29168$Xg.23657@trnddc06>,
Bill Cunningham <so**@net.comwrote:
> 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*/

Nov 25 '07 #4
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

Nov 25 '07 #5
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.
Nov 25 '07 #6
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 ---
Nov 26 '07 #7
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.
Nov 26 '07 #8
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);
Nov 26 '07 #9
"CBFalconer" <cb********@yahoo.comschrieb im Newsbeitrag
news:47***************@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 helpful answer 8-(
Fortunatly others had been far more helpfull in pointing out the typo(s)

Bye, Jojo
Nov 26 '07 #10
"Martin Ambuhl" <ma*****@earthlink.netschrieb im Newsbeitrag
news:5q*************@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
Nov 26 '07 #11
"Joe Wright" <jo********@comcast.netschrieb im Newsbeitrag
news:27******************************@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-)
Nov 26 '07 #12
Joachim Schmitz wrote:
"Martin Ambuhl" <ma*****@earthlink.netschrieb im Newsbeitrag
news:5q*************@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.
Nov 26 '07 #13
In article <fi**********@online.de>, Joachim Schmitz
<no*********@schmitz-digital.dewrote on Monday 26 Nov 2007 1:05 pm:
"Martin Ambuhl" <ma*****@earthlink.netschrieb im Newsbeitrag
news:5q*************@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.

Nov 26 '07 #14
Joachim Schmitz said:
"Joe Wright" <jo********@comcast.netschrieb 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
Nov 26 '07 #15
"Richard Heathfield" <rj*@see.sig.invalidschrieb im Newsbeitrag
news:r5******************************@bt.com...
Joachim Schmitz said:
>"Joe Wright" <jo********@comcast.netschrieb 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
Nov 26 '07 #16
"Martin Ambuhl" <ma*****@earthlink.netschrieb im Newsbeitrag
news:5q*************@mid.individual.net...
Joachim Schmitz wrote:
>"Martin Ambuhl" <ma*****@earthlink.netschrieb im Newsbeitrag
news:5q*************@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
Nov 26 '07 #17

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

Similar topics

5
by: David | last post by:
this phrase has been mentioned many times in this NG and it seems like everyone know what it's. is it a book? a standard? or a guide of some sort? where can i read more about K&R2? thanks!
12
by: Chris Readle | last post by:
Ok, I've just recently finished a beginning C class and now I'm working through K&R2 (alongside the C99 standard) to *really* learn C. So anyway, I'm working on an exercise in chapter one which...
16
by: TTroy | last post by:
I FOUND MAJOR ERRORS in K&R2 (making it almost useless for the herein mentioned topics). K&R2 Section 5.9 Pointers vs. Multidimension Arrays starts of like this... "Newcomers to C are...
3
by: Sunny | last post by:
Hi, Well this might look like a dumb question to 99.99% of u but what exactly is K&R2 and where can I get it? Secondly alot of people say that you can learn by reading good books on C. I know...
16
by: Josh Zenker | last post by:
This is my attempt at exercise 1-10 in K&R2. The code looks sloppy to me. Is there a more elegant way to do this? #include <stdio.h> /* copies input to output, printing */ /* series of...
2
by: arnuld | last post by:
there is a solution on "clc-wiki" for exercise 1.17 of K&R2: http://clc-wiki.net/wiki/K%26R2_solutions:Chapter_1:Exercise_17 i see this uses pointers whereas K&R2 have not discussed pointers...
8
by: arnuld | last post by:
i have created a solutions myself. it compiles without any trouble and runs but it prints some strange characters. i am not able to find where is the trouble. ...
19
by: arnuld | last post by:
this programme runs without any error but it does not do what i want it to do: ------------- PROGRAMME -------------- /* K&R2, section 1.6 Arrays; Exercise 1-13. STATEMENT: Write a program...
24
by: Anthony Irwin | last post by:
Hi all, I have been going through the k&r2 book and all the examples are done with main() instead of int main(void) and k&r2 in the start of chapter 1 does not return 0 so I haven't yet either....
15
by: arnuld | last post by:
STATEMENT: Write the function strindex(s, t), which returns the position of the rightmost occurence of t in s, or -1 if there is none. PURPOSE: this program prints the index of the rightmost...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.