problem related to printf!! why is it so???

Discussion in 'C Programming' started by Manohar S, Jan 28, 2004.

  1. Manohar S

    Manohar S Guest

    It is a problem related to printf, and buffering to the printf statements
    Look through this program.
    main()
    {
    int pid;
    int loop,max=3;

    for(loop = 0; loop <max;loop++)
    {
    pid = fork();
    if(pid < 0)
    printf("\nThe greatest fork error of the decade");
    else if(pid==0)
    {
    printf("\nI am a child");
    goto out;
    }
    else
    {
    printf("\nI have grown up");
    }
    }
    out:
    }

    output:
    I am a child
    I have grown up
    I am a childI have grown up
    I have grown up
    I am a childI have grown up
    I have grown up

    the same program with '\n' placed at the end of printf
    main()
    {
    int pid;
    int loop,max=3;

    for(loop = 0; loop <max;loop++)
    {
    pid = fork();
    if(pid < 0)
    printf("The greatest fork error of the decade\n");
    else if(pid==0)
    {
    printf("I am a child\n");
    goto out;
    }
    else
    {
    printf("I have grown up\n");
    }
    }
    out:
    }

    output:
    I am a child
    I have grown up
    I am a child
    I have grown up
    I am a child
    I have grown up

    why is this difference???
    could anyone please explain.....
    Manohar S, Jan 28, 2004
    #1
    1. Advertising


  2. > It is a problem related to printf, and buffering to the printf statements
    > Look through this program.
    > main()
    > {
    > int pid;
    > int loop,max=3;
    >
    > for(loop = 0; loop <max;loop++)
    > {
    > pid = fork();
    > if(pid < 0)
    > printf("\nThe greatest fork error of the decade");
    > else if(pid==0)
    > {
    > printf("\nI am a child");
    > goto out;
    > }
    > else
    > {
    > printf("\nI have grown up");
    > }
    > }
    > out:
    > }
    >
    > output:
    > I am a child
    > I have grown up
    > I am a childI have grown up
    > I have grown up
    > I am a childI have grown up
    > I have grown up
    >
    > the same program with '\n' placed at the end of printf
    > main()
    > {
    > int pid;
    > int loop,max=3;
    >
    > for(loop = 0; loop <max;loop++)
    > {
    > pid = fork();
    > if(pid < 0)
    > printf("The greatest fork error of the decade\n");
    > else if(pid==0)
    > {
    > printf("I am a child\n");
    > goto out;
    > }
    > else
    > {
    > printf("I have grown up\n");
    > }
    > }
    > out:
    > }
    >
    > output:
    > I am a child
    > I have grown up
    > I am a child
    > I have grown up
    > I am a child
    > I have grown up
    >
    > why is this difference???
    > could anyone please explain.....


    Yes I can explain:

    If you understand the concept of buffering, you will come
    know to why the above programs behaves like this.

    Streams are of two types: buffered and unbuffered. Buffered
    streams are flushed when any of the following conditions are met:

    * The buffer is full
    * When '\n' is encounterd, if the stream is line buffered
    * When a function to read from stdin is invoked
    * When the program exits
    * If the default flushing, i.e., buffering, behaviour is modified by
    the setvbuf(3) or setbuf(3) library functions.

    Whereas, unbufferd stream are flushed as soon as the data arrive.
    Keeping above facts in mind, try tracing your program again.

    [OT]
    After forking, which process (parent or child) will execute first can
    not be anticipated.
    [/OT]

    --
    Vijay Kumar R Zanvar
    My Home Page - http://www.geocities.com/vijoeyz/
    Vijay Kumar R Zanvar, Jan 28, 2004
    #2
    1. Advertising

  3. Manohar S

    Jack Klein Guest

    On 28 Jan 2004 01:54:36 -0800, (Manohar S)
    wrote in comp.lang.c:

    > It is a problem related to printf, and buffering to the printf statements
    > Look through this program.
    > main()
    > {
    > int pid;
    > int loop,max=3;
    >
    > for(loop = 0; loop <max;loop++)
    > {
    > pid = fork();


    [snip]

    Your question is off-topic here, as there is no such function as
    fork() in the C language or library. It is a non-standard extension
    provided by your particular compiler and operating system, nothing at
    all to do with the language.

    Questions about extensions such as this should be asked in a support
    group for that particular platform. In this particular case I would
    suggest either news:comp.unix.programmer or
    news:comp.os.linux.development.apps, depending you your platform.

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
    Jack Klein, Jan 29, 2004
    #3
  4. Manohar S

    Jack Klein Guest

    On Wed, 28 Jan 2004 15:55:18 +0530, "Vijay Kumar R Zanvar"
    <> wrote in comp.lang.c:

    >
    > > It is a problem related to printf, and buffering to the printf statements
    > > Look through this program.
    > > main()
    > > {
    > > int pid;
    > > int loop,max=3;
    > >
    > > for(loop = 0; loop <max;loop++)
    > > {
    > > pid = fork();


    [snip non-standard, off-topic code]

    > Yes I can explain:


    [snip]

    Please don't, as it is completely off-topic here. The proper thing to
    do with off-topic posts about non-standard extensions is to direct the
    poster to a group that supports the compiler/OS combination that
    provides them, not to provide off-topic answers here.

    > [OT]
    > After forking, which process (parent or child) will execute first can
    > not be anticipated.
    > [/OT]


    Since you know it is off-topic and there is no forking in the C
    language, why do you pollute the group?

    --
    Jack Klein
    Home: http://JK-Technology.Com
    FAQs for
    comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
    comp.lang.c++ http://www.parashift.com/c -faq-lite/
    alt.comp.lang.learn.c-c++
    http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
    Jack Klein, Jan 29, 2004
    #4
  5. Manohar S

    EPerson Guest

    (Manohar S) wrote in message news:<>...
    > It is a problem related to printf, and buffering to the printf statements
    > Look through this program.
    > main()


    It's best to be more explicit here:

    int main(void)

    > {
    > int pid;
    > int loop,max=3;
    >
    > for(loop = 0; loop <max;loop++)
    > {
    > pid = fork();


    Non-standard function (off-topic in comp.lang.c).

    > if(pid < 0)
    > printf("\nThe greatest fork error of the decade");


    Undefined behavior. #include <stdio.h> above.

    > else if(pid==0)
    > {
    > printf("\nI am a child");
    > goto out;


    The effect of the goto can be achieved using a break statement.

    > }
    > else
    > {
    > printf("\nI have grown up");
    > }
    > }
    > out:


    Syntax error. You have a label without a statement.

    > }


    You should return 0 (or other suitable value) here.

    [snip output and alternative program]

    > why is this difference???
    > could anyone please explain.....


    Take this to an appropriate group. The semantics of fork() are off-topic here.

    --
    Eric Schmidt
    EPerson, Jan 29, 2004
    #5
  6. [..]
    > Please don't, as it is completely off-topic here. The proper thing to
    > do with off-topic posts about non-standard extensions is to direct the
    > poster to a group that supports the compiler/OS combination that
    > provides them, not to provide off-topic answers here.
    >
    > > [OT]
    > > After forking, which process (parent or child) will execute first can
    > > not be anticipated.
    > > [/OT]

    >
    > Since you know it is off-topic and there is no forking in the C
    > language, why do you pollute the group?


    My aim was not to pollute. Next time I would do as you have
    adviced, or will try mailing the answer personally. Thank you.

    --
    Vijay Kumar R Zanvar
    Vijay Kumar R Zanvar, Jan 29, 2004
    #6
  7. Manohar S

    Bob Crowley Guest

    (EPerson) wrote in message news:<>...
    >


    Sorry to get off the topic, but as an absolute beginner teaching
    myself to program in C, I would like to know why I can get numbers to
    add together either as declared variables, or as mathematical
    functions in "printf", but find I cannot get them to multiply or
    divide.

    Is there an additional switch I need. I have included <math.h> but I
    don't think it is necessary for these simple operations.

    I'd appreciate advice.

    Bob Crowley.
    Bob Crowley, Jan 29, 2004
    #7
  8. Bob Crowley wrote:
    > Sorry to get off the topic, but as an absolute beginner teaching
    > myself to program in C, I would like to know why I can get numbers to
    > add together either as declared variables, or as mathematical
    > functions in "printf", but find I cannot get them to multiply or
    > divide.


    It's not clear (to me, at least) what you mean. Could you post some
    code to illustrate the problem?

    Jeremy.
    Jeremy Yallop, Jan 29, 2004
    #8
  9. On 29 Jan 2004 05:55:19 -0800, in comp.lang.c ,
    (Bob Crowley) wrote:

    > (EPerson) wrote in message news:<>...
    >>

    >
    >Sorry to get off the topic, but as an absolute beginner teaching
    >myself to program in C, I would like to know why I can get numbers to
    >add together either as declared variables, or as mathematical
    >functions in "printf", but find I cannot get them to multiply or
    >divide.


    You're using the operators * and / to do multiplication and division,
    right?


    --
    Mark McIntyre
    CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
    CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>


    ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
    ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
    Mark McIntyre, Jan 29, 2004
    #9
  10. Manohar S

    Bob Crowley Guest

    Mark McIntyre <> wrote in message news:<>...
    > On 29 Jan 2004 05:55:19 -0800, in comp.lang.c ,
    > (Bob Crowley) wrote:
    >
    > > (EPerson) wrote in message news:<>...
    > >>

    > >
    > >Sorry to get off the topic, but as an absolute beginner teaching
    > >myself to program in C, I would like to know why I can get numbers to
    > >add together either as declared variables, or as mathematical
    > >functions in "printf", but find I cannot get them to multiply or
    > >divide.

    >
    > You're using the operators * and / to do multiplication and division,
    > right?
    >
    >
    > --
    > Mark McIntyre
    > CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
    > CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>
    >
    >
    > ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
    > http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
    > ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---


    The problem is in a text book I am using, namely to find out
    "5/12*68".

    My coding is as follows

    #include <stdio.h>
    #include <math.h> COMMENT - should not be necessary

    main(){

    float answer;

    answer = 5/12*68;

    printf("Five eighths of sixty eight is %f\n", answer);

    }


    END OF CODING

    The first time I tried it I did not use a variable, but simply had
    5/12*68 in the printf statement where the variable name "answer" is
    now.

    I either got 0.000000 or -1.9xxxxx as the answer, whereas it should be
    28+.

    I also changed the / and * signs to + to see what would happen, and
    got 85 which is correct. So the program worked when I used the +
    signs for addition, but not when I used / or * for division and
    multiplication.

    I am using Redhat Linux 8, with the gcc C compiler, and compiling with

    gcc -o object.o source.c


    As I said, I'd appreciate knowing why the program won't allow * or /
    to work.

    Bob Crowley.
    Bob Crowley, Jan 30, 2004
    #10
  11. Bob Crowley <> scribbled the following:
    > Mark McIntyre <> wrote in message news:<>...
    >> On 29 Jan 2004 05:55:19 -0800, in comp.lang.c ,
    >> (Bob Crowley) wrote:
    >> > (EPerson) wrote in message news:<>...
    >> >Sorry to get off the topic, but as an absolute beginner teaching
    >> >myself to program in C, I would like to know why I can get numbers to
    >> >add together either as declared variables, or as mathematical
    >> >functions in "printf", but find I cannot get them to multiply or
    >> >divide.

    >>
    >> You're using the operators * and / to do multiplication and division,
    >> right?


    > The problem is in a text book I am using, namely to find out
    > "5/12*68".


    > My coding is as follows


    > #include <stdio.h>
    > #include <math.h> COMMENT - should not be necessary


    > main(){


    > float answer;


    > answer = 5/12*68;


    The problem here is that 5/12*68 is an integer expression. 5/12 is
    an integer division, and it's perfomed as such, yielding a result of
    0. You then multiply 0 by 68, yielding 0.
    Then this 0 is assigned to a float variable. Assigning it to a float
    does not magically go back and redo all the calculations as a float
    expression.
    You need to change the integer expression into a float expression.
    This can be done in several ways. Either cast the 5 or the 12 to
    float, or write 5.0 or 12.0 instead of 5 or 12.

    > printf("Five eighths of sixty eight is %f\n", answer);


    Shouldn't that be five twelfths?

    --
    /-- Joona Palaste () ------------- Finland --------\
    \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
    "All that flower power is no match for my glower power!"
    - Montgomery Burns
    Joona I Palaste, Jan 30, 2004
    #11
  12. Manohar S

    Dan Pop Guest

    In <> (Bob Crowley) writes:

    >The problem is in a text book I am using, namely to find out
    >"5/12*68".
    >
    >My coding is as follows
    >
    >#include <stdio.h>
    >#include <math.h> COMMENT - should not be necessary


    It is NOT necessary!

    >main(){
    >
    >float answer;
    >
    >answer = 5/12*68;

    ^^^^^^^
    This is an integer expression and it is evaluated as such. 5 / 12 yields
    0 in integer arithmetic, so the final result is 0. This result is
    converted to float and assigned to answer.

    Use floating point constants instead, to force the evaluation of the
    expression as a floating point expression.

    >printf("Five eighths of sixty eight is %f\n", answer);
    >
    >}
    >
    >
    >END OF CODING
    >
    >The first time I tried it I did not use a variable, but simply had
    >5/12*68 in the printf statement where the variable name "answer" is
    >now.


    That's MUCH worse: %f expects a double argument, not an integer one.
    If you used gcc correctly, it would have warned you.

    >I either got 0.000000 or -1.9xxxxx as the answer, whereas it should be
    >28+.


    Nope, the correct result in C is 0.

    >I also changed the / and * signs to + to see what would happen, and
    >got 85 which is correct. So the program worked when I used the +
    >signs for addition, but not when I used / or * for division and
    >multiplication.


    Depending on the actual expression, even * and / give the expected
    result when misused. Try

    answer = 60 / 5 * 3;

    and I bet you'll get the expected result, because 60 / 5 yields the same
    value as 60.0 / 5.0 (but with a different type).

    >I am using Redhat Linux 8, with the gcc C compiler, and compiling with
    >
    >gcc -o object.o source.c


    It is highly misleading to call object.o an executable file, which is
    what your command will produce in the absence of the -c option.

    NEVER omit the -Wall -O options when compiling with gcc.

    fangorn:~/tmp 259> cat test.c
    #include <stdio.h>

    int main()
    {
    printf ("%f\n", 5/12*68);
    return 0;
    }
    fangorn:~/tmp 260> gcc test.c
    fangorn:~/tmp 261> gcc -Wall test.c
    test.c: In function `main':
    test.c:5: warning: double format, different type arg (arg 2)

    And, of course, NEVER ignore any warning produced by gcc -Wall -O.

    >As I said, I'd appreciate knowing why the program won't allow * or /
    >to work.


    They do work, but they work as specified by the C language definition,
    not according to your misconceptions. C doesn't support the arithmetic
    you've learned in grade school. It supports two different types of
    arithmetic (ignoring pointer arithmetic): integer arithmetic and floating
    point arithmetic and neither of them has the semantics of arithmetic on
    real numbers.

    Never forget: when two operands have the same arithmetic type, the
    +, -, * and / operators yield a value of the *same* type, even if the
    value is used as initialiser to an object of a different arithmetic type.

    Dan
    --
    Dan Pop
    DESY Zeuthen, RZ group
    Email:
    Dan Pop, Jan 30, 2004
    #12
  13. Manohar S

    Grumble Guest

    Dan Pop wrote:

    > NEVER omit the -Wall -O options when compiling with gcc.


    Why do you recommend the -O flag?

    What about the -W flag?
    Grumble, Jan 30, 2004
    #13
  14. Manohar S

    Dan Pop Guest

    In <bvdo5k$qmi$> Grumble <> writes:

    >Dan Pop wrote:
    >
    >> NEVER omit the -Wall -O options when compiling with gcc.

    >
    >Why do you recommend the -O flag?


    Without it, gcc is not able to report the usage of uninitialised
    variables:

    fangorn:~/tmp 279> cat test.c
    int main()
    {
    int rc;
    return rc;
    }
    fangorn:~/tmp 280> gcc -Wall test.c
    fangorn:~/tmp 281> gcc -Wall -O test.c
    test.c: In function `main':
    test.c:3: warning: `rc' might be used uninitialized in this function

    And this particular class of errors occurs quite often in beginner
    programs.

    >What about the -W flag?


    From the gcc man page:

    The following -W... options are not implied by -Wall. Some of
    them warn about constructions that users generally do not consider
    questionable, but which occasionally you might wish to check for;
    others warn about constructions that are necessary or hard to
    avoid in some cases, and there is no simple way to modify the code
    to suppress the warning.

    -W Print extra warning messages for these events:
    ...

    I couldn't agree more with the gcc people: some of the -W warnings are
    about perfectly good constructs and the only way to shut them up is by
    reducing the quality/maintainability of the code (e.g. by introducing
    *unneeded* casts).

    Whoever decided not to enable everything with -Wall certainly knew
    what he was doing.

    Dan
    --
    Dan Pop
    DESY Zeuthen, RZ group
    Email:
    Dan Pop, Jan 30, 2004
    #14
  15. "Jack Klein" <> wrote in message
    news:...
    > On Wed, 28 Jan 2004 15:55:18 +0530, "Vijay Kumar R Zanvar"
    > <> wrote in comp.lang.c:
    > >
    > > > It is a problem related to printf, and buffering to the printf

    statements
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    > > > Look through this program.
    > > > main()
    > > > {
    > > > int pid;
    > > > int loop,max=3;
    > > >
    > > > for(loop = 0; loop <max;loop++)
    > > > {
    > > > pid = fork();

    >
    > [snip non-standard, off-topic code]
    >
    > > Yes I can explain:

    >
    > [snip]
    >
    > Please don't, as it is completely off-topic here. The proper thing to
    > do with off-topic posts about non-standard extensions is to direct the
    > poster to a group that supports the compiler/OS combination that
    > provides them, not to provide off-topic answers here.


    Jack, would you please cool down. fork() is OT here indeed, but the OP's
    question was about printf(), to which Vijay gave a perfectly topical
    answer.

    The moral is that the question may still be topical, even if the context
    is not.

    Peter
    Peter Pichler, Jan 30, 2004
    #15
  16. Manohar S

    Lew Pitcher Guest

    Bob Crowley wrote:
    > (EPerson) wrote in message news:<>...
    >
    >
    > Sorry to get off the topic, but as an absolute beginner teaching
    > myself to program in C, I would like to know why I can get numbers to
    > add together either as declared variables, or as mathematical
    > functions in "printf", but find I cannot get them to multiply or
    > divide.
    >
    > Is there an additional switch I need. I have included <math.h> but I
    > don't think it is necessary for these simple operations.


    No, <math.h> isn't necessary for addition, subtraction, multiplication or division.

    ~/code/aaa $ cat math.c
    #include <stdio.h>
    #include <stdlib.h>

    int main(void)
    {
    printf("10 + 7 = %d\t",(10 + 7));
    printf("10. + 7. = %f\n",(10. + 7.));
    printf("10 - 7 = %d\t",(10 - 7));
    printf("10. - 7. = %f\n",(10. - 7.));
    printf("10 * 7 = %d\t",(10 * 7));
    printf("10. * 7. = %f\n",(10. * 7.));
    printf("10 / 7 = %d\t",(10 / 7));
    printf("10. / 7. = %f\n",(10. / 7.));

    return EXIT_SUCCESS;
    }

    ~/code/aaa $ cc -o math math.c
    ~/code/aaa $ math
    10 + 7 = 17 10. + 7. = 17.000000
    10 - 7 = 3 10. - 7. = 3.000000
    10 * 7 = 70 10. * 7. = 70.000000
    10 / 7 = 1 10. / 7. = 1.428571

    Seems simple enough, though.

    HTH

    --
    Lew Pitcher

    Master Codewright and JOAT-in-training
    Registered Linux User #112576 (http://counter.li.org/)
    Slackware - Because I know what I'm doing.
    Lew Pitcher, Jan 30, 2004
    #16
  17. On 30 Jan 2004 02:24:48 -0800, in comp.lang.c ,
    (Bob Crowley) wrote:

    >The problem is in a text book I am using, namely to find out
    >"5/12*68".
    >
    >My coding is as follows
    >
    >answer = 5/12*68;


    This is a FAQ. Summary: 5,12, and 68 are all integers. So the copmiler
    does integer maths. 5/12 = 0.
    If you want to do floating point maths, use floating point values.
    answer = 5.0/12.0*68.0;

    >As I said, I'd appreciate knowing why the program won't allow * or /
    >to work.


    They're working perfectly, you're jusst using them wrong !

    --
    Mark McIntyre
    CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
    CLC readme: <http://www.angelfire.com/ms3/bchambless0/welcome_to_clc.html>


    ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
    ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
    Mark McIntyre, Jan 31, 2004
    #17
  18. Manohar S

    Bob Crowley Guest

    Lew Pitcher <> wrote in message news:<6s4x6-4.ca>...
    > Bob Crowley wrote:
    > > (EPerson) wrote in message news:<>...
    > >
    > >
    > > Sorry to get off the topic, but as an absolute beginner teaching
    > > myself to program in C, I would like to know why I can get numbers to
    > > add together either as declared variables, or as mathematical
    > > functions in "printf", but find I cannot get them to multiply or
    > > divide.
    > >
    > > Is there an additional switch I need. I have included <math.h> but I
    > > don't think it is necessary for these simple operations.

    >
    > No, <math.h> isn't necessary for addition, subtraction, multiplication or division.
    >
    > ~/code/aaa $ cat math.c
    > #include <stdio.h>
    > #include <stdlib.h>
    >
    > int main(void)
    > {
    > printf("10 + 7 = %d\t",(10 + 7));
    > printf("10. + 7. = %f\n",(10. + 7.));
    > printf("10 - 7 = %d\t",(10 - 7));
    > printf("10. - 7. = %f\n",(10. - 7.));
    > printf("10 * 7 = %d\t",(10 * 7));
    > printf("10. * 7. = %f\n",(10. * 7.));
    > printf("10 / 7 = %d\t",(10 / 7));
    > printf("10. / 7. = %f\n",(10. / 7.));
    >
    > return EXIT_SUCCESS;
    > }
    >
    > ~/code/aaa $ cc -o math math.c
    > ~/code/aaa $ math
    > 10 + 7 = 17 10. + 7. = 17.000000
    > 10 - 7 = 3 10. - 7. = 3.000000
    > 10 * 7 = 70 10. * 7. = 70.000000
    > 10 / 7 = 1 10. / 7. = 1.428571
    >
    > Seems simple enough, though.
    >
    > HTH



    Thanks for your help everybody. I simply changed my input to include
    a decimal place eg. 5.0, 12.0, 68.0 and it worked perfectly. I'm a
    bit bamboozled why the compiler does not assume floating point maths
    when the integer is declared floating point, but I'll learn that as
    time goes by. Obviously the problem was included for this reason.

    I also tried including the -Wall switch as suggested, but seemed to
    come up with a lot of verbiage which meant little to me in my
    programming infancy, and the program worked when I tried it anyway.

    Bob Crowley
    Bob Crowley, Feb 1, 2004
    #18
  19. Manohar S

    CBFalconer Guest

    Bob Crowley wrote:
    >

    .... snip ...
    >
    > Thanks for your help everybody. I simply changed my input to include
    > a decimal place eg. 5.0, 12.0, 68.0 and it worked perfectly. I'm a
    > bit bamboozled why the compiler does not assume floating point maths
    > when the integer is declared floating point, but I'll learn that as
    > time goes by. Obviously the problem was included for this reason.


    If you pour an arbitrary liquid into your car engine, does it
    magically change to oil or water depending on which orifice you
    are filling?

    >
    > I also tried including the -Wall switch as suggested, but seemed to
    > come up with a lot of verbiage which meant little to me in my
    > programming infancy, and the program worked when I tried it anyway.


    Find out what that verbiage means and fix it, or you will remain
    in your infancy.

    --
    Chuck F () ()
    Available for consulting/temporary embedded and systems.
    <http://cbfalconer.home.att.net> USE worldnet address!
    CBFalconer, Feb 1, 2004
    #19
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    877
    Mark Rae
    Dec 21, 2006
  2. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,806
    Smokey Grindel
    Dec 2, 2006
  3. ben
    Replies:
    4
    Views:
    612
    Martin Ambuhl
    Jun 26, 2004
  4. whatluo

    (void) printf vs printf

    whatluo, May 26, 2005, in forum: C Programming
    Replies:
    29
    Views:
    1,238
  5. azza

    printf affects following printf/s

    azza, Oct 17, 2010, in forum: C Programming
    Replies:
    0
    Views:
    431
Loading...

Share This Page