Frustration with tutorial.

This is a discussion on Frustration with tutorial. within the C Programming forums, part of the General Programming Boards category; I got the book "C for Dummies volume II". printed in 1997. I'm using the djgpp compiler. It seems that ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Location
    Beaverton, Oregon, United States
    Posts
    158

    Frustration with tutorial.

    I got the book "C for Dummies volume II". printed in 1997. I'm using the djgpp compiler.

    It seems that djgpp doesn't recognize the 'strcmpi' function though it recognize 'strcmp'.

    Also while doing a small metric program that converts miles to kilometers, I get this:

    Code:
    Microsoft Windows 2000 [Version 5.00.2195]
    (C) Copyright 1985-2000 Microsoft Corp.
    
    C:\Documents and Settings\Bob L Woods>cd c:\djgpp
    
    C:\DJGPP>cd mystuff
    
    C:\DJGPP\Mystuff>gcc metric.c -o metric
    Cannot load VDM IPX/SPX support
    metric.c:14:9: warning: unknown escape sequence: '\040'
    metric.c: In function 'main':
    metric.c:5: warning: return type of 'main' is not 'int'
    
    C:\DJGPP\Mystuff>metric
    Enter a value in miles:18
    0.00 miles work out to 0.00 kilometers
    C:\DJGPP\Mystuff>
    Here is the source code:

    Code:
    void 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);
    }
    Can anyone tell me if its something I'm doing wrong or if perhaps my copy of DJGPP is missing files or corrupted?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,436
    strcmpi() is non-standard.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,649
    For the love of Pete, can you use Visual Studio? There are free versions now and everything.
    Oh, and before someone else says it, main should return int, not void (which djgpp is nicely letting you know!)
    Code:
    int main() 
    {
       return 0;
    }

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,449
    Code:
    metric.c:5: warning: return type of 'main' is not 'int'
    Code:
    void main()
    Does this tell you anything? No? Well, it should, because void main is undefined.
    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.

  5. #5
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    > For the love of Pete, can you use Visual Studio? There are free versions now and everything.
    Why? That's got nothing to do with his problem -- using VS wouldn't solve it either.

  6. #6
    Registered User
    Join Date
    Sep 2006
    Location
    Beaverton, Oregon, United States
    Posts
    158
    ok I'm not worried about the warnings. thanks for letting me know about the strcmpi being non standard. It's stricmp for standard right?

    Anyways, it still doesn't tell me why this particular program will not work. Any help anyone could give would be nice.

    I'll look into the Visual Studioo free version. Is it crippled in some way?

  7. #7
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,449
    Avoid void main.
    Yes, the free version is somewhat crippled. No MFC, no resource editor being the biggest you new programmers. Don't worry, it's still plenty useful.
    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.

  8. #8
    Registered User
    Join Date
    Jan 2008
    Posts
    287
    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

    The rest of your problems would be solved by writing proper code I suspect:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(void)
    {
    	char input[20];
    	double miles, kilometers;
    
    	printf("Enter a value in miles:");
    	miles = atof(gets(input));
    
    	kilometers=miles*1.609;
    
    	printf("&#37;.2f miles work out to %.2f kilometers",miles,kilometers);
    
            return 0;  // [edit] Hah, forgot the return 0 -- what do I know about proper code??? [/edit]
    }
    Last edited by arpsmack; 03-17-2008 at 03:17 PM.

  9. #9
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,449
    Do not use gets. It is incredibly unsafe. Use fgets.
    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.

  10. #10
    Registered User
    Join Date
    Sep 2006
    Location
    Beaverton, Oregon, United States
    Posts
    158
    sigh

  11. #11
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    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
    */
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  12. #12
    Registered User
    Join Date
    Sep 2006
    Location
    Beaverton, Oregon, United States
    Posts
    158
    Quote Originally Posted by Elysia View Post
    Avoid void main.
    Yes, the free version is somewhat crippled. No MFC, no resource editor being the biggest you new programmers. Don't worry, it's still plenty useful.
    Ok thanks, took a peek and I'll clean that crap out a little later.

  13. #13
    Registered User
    Join Date
    Sep 2006
    Location
    Beaverton, Oregon, United States
    Posts
    158
    It's odd, because this works:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    main()
    {
    	char	
    	AmountDue[20];
    	double	amountdue;
    
    	printf("Enter the amount due: ");
    	scanf("&#37;s",AmountDue);
    
    	amountdue=atof(AmountDue);
    	printf("The amount due is '%s' -> %g\n",AmountDue, amountdue);
    
    }
    But the first posted code acts like I've put in a non-numerical string, with nothing to convert to float.

  14. #14
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    Quote Originally Posted by A34Chris View Post
    It's odd, because this works:
    And what will happen with this "working" code if the user inputs string of 40 characters?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  15. #15
    Registered User
    Join Date
    Sep 2006
    Location
    Beaverton, Oregon, United States
    Posts
    158
    Quote Originally Posted by vart View Post
    And what will happen with this "working" code if the user inputs string of 40 characters?
    Buffer overflow obviously. But its just a tut to get you acquainted with things.

Page 1 of 2 12 LastLast
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, 06: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, 08:40 PM
  4. Problem with tutorial (Vector class)
    By OdyTHeBear in forum C++ Programming
    Replies: 4
    Last Post: 12-18-2002, 01: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21