Newb problem

Haynesworth's Avatar, Join Date: Dec 2006
Newbie Member
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.
0
DaWei's Avatar, Join Date: Dec 2006
Team Leader
Perhaps you should show your actual, exact command line.
0
Haynesworth's Avatar, Join Date: Dec 2006
Newbie Member
Quote:
Originally Posted by DaWei
Perhaps you should show your actual, exact command line.
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.
0
DaWei's Avatar, Join Date: Dec 2006
Team Leader
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>
0
Haynesworth's Avatar, Join Date: Dec 2006
Newbie Member
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.
0
DaWei's Avatar, Join Date: Dec 2006
Team Leader
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.
0
Haynesworth's Avatar, Join Date: Dec 2006
Newbie Member
OK, I'll try that. Thanks for all your help.