Newb problem

Discussion in 'C' started by Haynesworth, Dec 23, 2006.

  1. Haynesworth

    Haynesworth New Member

    Joined:
    Dec 23, 2006
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Hey, I realize this is probably a stupid problem, but I can't figure it out. I'm coding in C, and when I try to compile and link a program (using Dev-C++), I type in gcc (name of program).c -o (name of program). It works to compile it, but when I try to use the command I gave it to run the program, it doesn't work. Instead, the program is saved as just "4" on my computer. If I type in 4, the program runs. However, whenever I create a new program and try to compile and link it, the program is saved as "4" and it replaces the program of the old one. I can't seem to figure out what's going on. I was wondering if anyone could help. Thanks.
     
  2. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    Perhaps you should show your actual, exact command line.
     
  3. Haynesworth

    Haynesworth New Member

    Joined:
    Dec 23, 2006
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    If I have a program called EXAMPLE.C that I'm trying to compile and link, I enter gcc example.c -o example into my command prompt. The program successfully compiles, but when I try to use the command "example", I get an error message saying "'example' is not recognized as an internal or external command, operable program or batch file." Then, when I check the folder in which I'm saving my programs, I see a program just named 4. When I enter 4 into the command prompt, my program runs. Any time I try to create a new program and compile and link it this way, it doesn't work but replaces the old "4" program. I can't figure out what's going on.
     
  4. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    Code:
    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.
    
    E:\Documents and Settings\David>cd E:\Dev-cpp\Projects
    
    E:\Dev-Cpp\Projects>copy con example.c
    #include <stdio.h>
    
    int main ()
    {
            puts ("Hello, Dev");
            return 0;
    }
    ^Z
            1 file(s) copied.
    
    E:\Dev-Cpp\Projects>e:\dev-cpp\bin\gcc example.c -o example
    
    E:\Dev-Cpp\Projects>example
    Hello, Dev
    
    E:\Dev-Cpp\Projects>
    
     
  5. Haynesworth

    Haynesworth New Member

    Joined:
    Dec 23, 2006
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    This is my coding of the program, saved as EXAMPLE.C on my computer:

    Code:
    #include <stdio.h>
    
    int main()
    {
    printf("This is an example");
    return(0);
    }
    
    And this is my attempt to compile it, and what happens:

    Code:
    C:\Documents and Settings\Sean\My Documents>cd prog/c/learn
    
    C:\Documents and Settings\Sean\My Documents\prog\c\learn>gcc example.c -o example
    
    C:\Documents and Settings\Sean\My Documents\prog\c\learn>example
    'example' is not recognized as an internal file or external command, 
    operable program or batch file.
    
    C:\Documents and Settings\Sean\My Documents\prog\c\learn>4
    This is an example
    C:\Documents and Settings\Sean\My Documents\prog\c\learn>
    
    So the program is compiled, but when I try to use the command I gave it, "example", it doesn't work. Instead it is saved as a program called 4, which works when I try to run the program.
     
  6. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    Completely remove Dev-C++ and reinstall. I (and others) have had some weird problems crop up with it, but not this particular one. In my case, it quit handling the chdir stuff right while running the make file. Don't try to install over it; remove the old version. If that doesn't clear your problem, then check with Dev-Cpp support; they should have heard of any weirdness that's common.
     
  7. Haynesworth

    Haynesworth New Member

    Joined:
    Dec 23, 2006
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    OK, I'll try that. Thanks for all your help.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice