Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Newb problem (http://www.go4expert.com/forums/newb-problem-t2333/)

Haynesworth 23Dec2006 23:51

Newb problem
 
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.

DaWei 24Dec2006 02:20

Re: Newb problem
 
Perhaps you should show your actual, exact command line.

Haynesworth 24Dec2006 23:17

Re: Newb problem
 
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.

DaWei 25Dec2006 08:30

Re: Newb problem
 
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>


Haynesworth 25Dec2006 22:26

Re: Newb problem
 
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.

DaWei 26Dec2006 08:06

Re: Newb problem
 
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.

Haynesworth 26Dec2006 23:39

Re: Newb problem
 
OK, I'll try that. Thanks for all your help.


All times are GMT +5.5. The time now is 23:01.