Thread: Falling at the first hurdle

  1. #1
    Registered User screwloose's Avatar
    Join Date
    Apr 2014
    Posts
    3

    Falling at the first hurdle

    Hi,
    I'm an absolute beginner (well, apart from doing some Basic programming many years ago).

    At the moment I'm falling at the first hurdle – trying to compile C, using the Dummies guide (don't laugh, please!).
    I'm reasonably proficient on a PC – I'm running Windows 7 64 bit. The author suggests using MinGW to compile C.
    Downloaded and installed the compiler, opened a DOS window and the command “gcc goodbye.c -o goodbye” as per the authors instructions.


    The first example in the book is:

    Code:
     #include <stdio.h>
     
    
     int main()
     {
     printf(“Goodbye, cruel world!\n”);
     return(0);
     }
    I used notepad, saved as text using ANSI, then tried to compile.
    The errors thrown up are in the attached screenshot (not that I understand any of them yet).
    For all I know maybe I haven't installed MinGW correctly?
    Attached Images Attached Images Falling at the first hurdle-goodbye1-png 

  2. #2
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    You're using "smart quotes". You want

    Code:
    printf("Goodbye, cruel world!\n");
    and not

    Code:
    printf(Goodbye, cruel world!\n);

  3. #3
    Registered User Alpo's Avatar
    Join Date
    Apr 2014
    Posts
    877
    @screwloose - I just posted a thread about how hard the exercises in k&r are and then saw this wonderful thread of yours that took all the frustration away lol, thanks.

    Have you looked into CodeBlocks? It is a free compiler that works well with Windows (I think XP and on), and is really beginner friendly. Your program is fine I think, although I don't think you would have to put the value main is returning in parenthesis.

    Isn't Mingw a debugger (a tool to help you figure out things wrong with you code)? It seems to be taking the words in the printf statement as variables..?

  4. #4
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Quote Originally Posted by Alpo View Post
    Your program is fine I think, although I don't think you would have to put the value main is returning in parenthesis.
    Nope, it's not fine for the reason I specified. The errors after the stray are caused by the compiler getting confused when it encountered the unknown character (and again when the is encountered). You're right about the return value not requiring the parenthesis -- return is a keyword, not a function -- but that won't cause an error; it'll just irritate people.

    Quote Originally Posted by Alpo View Post
    Isn't Mingw a debugger (a tool to help you figure out things wrong with you code)? It seems to be taking the words in the printf statement as variables..?
    Well, it does include a debugger (gdb). And a compiler. And some other tools.

    MinGW | Minimalist GNU for Windows
    MinGW, a contraction of "Minimalist GNU for Windows", is a minimalist development environment for native Microsoft Windows applications.


    MinGW provides a complete Open Source programming tool set which is suitable for the development of native MS-Windows applications, and which do not depend on any 3rd-party C-Runtime DLLs. (It does depend on a number of DLLs provided by Microsoft themselves, as components of the operating system; most notable among these is MSVCRT.DLL, the Microsoft C runtime library. Additionally, threaded applications must ship with a freely distributable thread support DLL, provided as part of MinGW itself).
    Last edited by Hodor; 04-10-2014 at 11:55 PM.

  5. #5
    Registered User screwloose's Avatar
    Join Date
    Apr 2014
    Posts
    3
    Hi,
    So far I'm not doing very well at all.
    I thought all the code I had copied from the Dummies book should be inside the code tag, but not according to your comment?
    So why is only some of the code inside the code tag?

  6. #6
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Copy and paste:

    Code:
    #include <stdio.h>
    
    
    int main(void)
    
    {
    
        printf("Goodbye, cruel world!\n");
    
        
        return 0;
    
    }
    Your Mingw compiler is working fine (as far as I can tell)

  7. #7
    Registered User Alpo's Avatar
    Join Date
    Apr 2014
    Posts
    877
    @Hodor- You are right, I was looking right at and missed it. You ninja posted me (is that what they call it on the internets still?)

    @screwloose- was there more code you posted that didn't show up? hodor was talking about the type of quotes you were using with the printf function (not the quote of the stuff you posted between code tags), they caused it not to recognize the string, trying to pass the arguments as variables.
    You can tell because it says that Goodbye is undeclared. Any time you get that error it is usually a variable you have forgotten to give a value to, or a case of mistaken identity like in this case.

  8. #8
    Registered User screwloose's Avatar
    Join Date
    Apr 2014
    Posts
    3
    Many thanks for all who replied to my OP regarding my first attempt at compiling C.

    After a few hours I have solved my own problem!
    I kept re-writing each line of code until it compiled correctly. Then on the erroroneous line, I changed one character at a time until I discover the error.
    It was the speech marks (in the printf command) which caused the failure.
    I had copied and pasted the very short program from elsewhere and that used those curly spechmarks - they look like 66 and 99 - and then I was doomed to failure.
    Replacing them with the straight-type speechmark (vertical, no curls), then all is fine.

    That now raises another question:
    What is the name of the two different types of speechmarks, and how can I ensure I use the correct ones?
    This only occurs when copying & pasting text, and I have to change every instance. If I type it manually using notepad, that doesn't cause a problem.

    Thanks again for all the comments.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Switch Statement falling through all cases:
    By jocdrew21 in forum C++ Programming
    Replies: 8
    Last Post: 01-16-2014, 11:21 PM
  2. Replies: 3
    Last Post: 03-19-2012, 03:22 AM
  3. Gravity calculations for falling object
    By misterFry in forum Game Programming
    Replies: 7
    Last Post: 10-10-2010, 12:26 PM
  4. Monitor refresh falling out of sync
    By cboard_member in forum Tech Board
    Replies: 1
    Last Post: 04-16-2007, 10:25 AM
  5. Prices are falling!
    By Liger86 in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 02-17-2003, 12:40 PM

Tags for this Thread