whats wrong with

Discussion in 'Mac Programming' started by smogsy, Oct 15, 2008.

  1. smogsy macrumors 6502a

    Joined:
    Jan 8, 2008
    #1
    it runs ok but when inputting a number it goes to next line as it should but displays bus Error

    thanks.
     
  2. toddburch macrumors 6502a

    Joined:
    Dec 4, 2006
    Location:
    Katy, Texas
    #2
    Try this:
    Code:
    scanf("%d",[color=red]&[/color]Number);
    
    After you change it and see that it now works, come back here and tell me why so I know you understand why that fixed it.
     
  3. Darkroom Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #3
    besides missing the &number pointer...

    Code:
    /*Tells them Their Number*/
    printf("Your Number is" "%d",Number);
    weird quotes in there?

    try:

    Code:
    /*Tells them Their Number*/
    printf("Your Number is %d", Number);
    you can also use %i for integers... i always found using %d a little odd, although it's way common, and they both do the exact same thing, i just find it easier to associate Integers with the letter I...

    and don't forget the newline character "\n" after your sentence so the 2 output sentences don't run together:

    Code:
    printf("Your Number is %d[COLOR="Red"]\n[/COLOR]", Number);
     
  4. toddburch macrumors 6502a

    Joined:
    Dec 4, 2006
    Location:
    Katy, Texas
    #4
    Well, it is errant, but that's not the output the OP will get:

    Code:
    [i]Hello Welcome to my First Application
     Please Input a Number Between 0 & 10[/i]
    [b]4[/b]
    [i]Your Number is4OK You selected 4 Correctly[/i]
    The Debugger has exited with status 0.
    
     
  5. fimac macrumors member

    Joined:
    Jan 18, 2006
    Location:
    Finland
    #5
    Weird, perhaps, but the C compiler concatenates adjacent literal strings :)
     
  6. smogsy thread starter macrumors 6502a

    Joined:
    Jan 8, 2008
    #6
    it works after inserting the & any reason why it saying 90k? the first time?

    sorry still learning :D
     
  7. itickings macrumors 6502a

    itickings

    Joined:
    Apr 14, 2007
    #7
    It is actually saying 9 and then OK immediately afterwards. You have to specifically tell the computer to advance to the next row. If you don't, it will continue to write stuff directly after the last displayed character.
    Code:
    printf("Your Number is %d[B]\n[/B]",Number);
     

Share This Page