Results 1 to 2 of 2

Thread: scanf not reading input correctly

  1. #1
    Join Date
    Jan 2006
    Location
    11 N 78 E
    Posts
    110
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default scanf not reading input correctly

    I wrote a program:
    Qt Code:
    1. int main(void) {
    2. double iiput;
    3. printf("\n\nEnter a degree value: ");
    4. scanf("%14.10f", &iiput);
    5. printf("%14.10f\n", iiput);}
    To copy to clipboard, switch view to plain text mode 
    and the user-machine interaction upon compiling this was:
    Enter a degree value: 200.5896113248
    2.1702880859
    Please explain what I am doing wrong?
    Thank you.
    Penguin #395953 using Qt for open-source development on X11 using C++ and
    Python via PyQt

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: scanf not reading input correctly

    Make sure that you have all warnings turned on when you compile your program, then the compiler will tell what might be wrong:
    $ gcc -Wall a.c
    a.c: In function `main':
    a.c:6: warning: unknown conversion type character `.' in format
    a.c:6: warning: too many arguments for format
    a.c:7: warning: control reaches end of non-void function
    Try:
    Qt Code:
    1. scanf("%lf", &iiput);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QWT 5, QT3, SuSE 10.2. Crash and burn
    By DrMcCleod in forum Qwt
    Replies: 8
    Last Post: 7th September 2007, 20:53
  2. problem with reading input data in qt
    By Ahmad in forum Qt Programming
    Replies: 3
    Last Post: 9th April 2007, 10:58

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.