Thread: Frustration with tutorial.

  1. #16
    Registered User
    Join Date
    Sep 2006
    Location
    Beaverton, Oregon, United States
    Posts
    176
    Quote Originally Posted by Dave_Sinkula View Post
    Code:
    #include <stdio.h>
    
    int main()
    {
       char input[20];
       double miles,kilometers;
    
       printf("Enter a value in miles: ");
       fflush(stdout);
       if ( fgets(input, sizeof input, stdin) )
       {
          if ( sscanf(input, "%lf", &miles) == 1 )
          {
             kilometers = miles * 1.609;
             printf("%.2f miles work out to %.2f kilometers",miles,kilometers);
          }
       }
       return 0;
    }
    
    /* my output
    Enter a value in miles: 17.5
    17.50 miles work out to 28.16 kilometers
    */
    Thank you. This worked.

  2. #17
    Registered User
    Join Date
    Sep 2006
    Location
    Beaverton, Oregon, United States
    Posts
    176
    Quote Originally Posted by arpsmack View Post
    Referring to your "Cannot load VDM IPX/SPX support" problem, a quick google search for that exact string turned up this: http://rumkin.com/reference/problems/csnw.php

    Thanks. Got rid of tht crap.

  3. #18
    Registered User sndpchikane's Avatar
    Join Date
    Mar 2008
    Posts
    5

    Here is program

    Hi buddy

    here is your program after removing error.

    you forgot to include some usefull libraries

    Code:
    # include<stdio.h>
    # include<conio.h>
    # include<stdlib.h>
    
    
    main()
    {
    	char input[20];
    	double miles,kilometers;
    
    	printf("Enter a value in miles:");
    	miles=atof(gets(input));
    
    	kilometers=miles*1.609;
    
    	printf("%.2f miles work out to\ %.2f kilometers",miles,kilometers);
    	
    	getch();
    }

  4. #19
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by sndpchikane View Post
    Hi buddy

    here is your program after removing error.
    And making new ones...

    1. conio.h is not standard - better avoid
    2. main should be

    int main(void)

    3. do not use gets - ever - read FAQ

    4. getche not standard - use getchar()

    5. main should return int so better add
    return 0;
    at the end
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #20
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by A34Chris View Post
    Buffer overflow obviously. But its just a tut to get you acquainted with things.
    Yes, but please, do not teach bad practices. Avoid buffer overrun problems, for example.
    It's fine to post a dumbed down example, but don't post an example that's outright dangerous, such as those that are prone to buffer overflows.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My new website
    By joeprogrammer in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 03-17-2006, 07:38 PM
  2. Cprog tutorial: Design Patterns
    By maes in forum C++ Programming
    Replies: 7
    Last Post: 10-11-2004, 01:41 AM
  3. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 09:40 PM
  4. Problem with tutorial (Vector class)
    By OdyTHeBear in forum C++ Programming
    Replies: 4
    Last Post: 12-18-2002, 02:49 PM
  5. My DirectInput tutorial....
    By jdinger in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 06-18-2002, 11:32 PM