# Very Simple C program won't compile



## PC person (Feb 2, 2006)

Here's my source code. I'm using C for dummies, the big multi-chapter book

int main()
{
puts("Greetings human!");
return(0);
}

I'm using vim easy 7.2 and the directory of my compiler is C:\mingw\bin. I already set the path variable to account for this. When I go to C:\prog, where I put the source code file saved as dumb.c. I go it's directory, after typing cmd.exe in run, which is C:\prog and type gcc dumb.c -o dumb, and I get

gcc: dumb.c: No such file or directory
gcc: no input files

Any ideas why it's doing this? I'm told I have to leave a blank line after the second bracket (does it matter how many?)


----------



## Ninjaboi (Dec 27, 2010)

```
#include <iostream>

int main()
{
    puts("Greetings human!");
    return(0);
}
```
You forgot to include the file that 'puts()' uses. I'm assuming the book your reading through had the code you presented in one block as a part to show you something, but didn't present it as a whole program. Just copy and paste that code and you should be fine.


----------



## PC person (Feb 2, 2006)

Ninjaboi said:


> ```
> #include <iostream>
> 
> int main()
> ...


On the next page it introduces #include <stdio.h> but before that it tells you just to compile it. Either way it still isn't working for me. I tried it both with that and iostream and I still get the same error.


----------



## Ninjaboi (Dec 27, 2010)

Hmm...what compiler are you using? I've compiled perfectly in both Visual Studio 2008 as well as Dev-C++.


----------



## PC person (Feb 2, 2006)

Ninjaboi said:


> Hmm...what compiler are you using? I've compiled perfectly in both Visual Studio 2008 as well as Dev-C++.


Mingw


----------



## Ninjaboi (Dec 27, 2010)

Have you set your environment variables yet? Try this link to help you setup Mingw properly:

HOWTO Install the MinGW (GCC) Compiler Suite | MinGW

If you've set everything up correctly, maybe try compiling this code:


```
#include <iostream>

int main()
{

     printf("Hello World!");
     return 0;

}
```
If that still doesn't work, tell me what error message(s) you receive when you try to compile.

If you get no compile error, then can you tell me what happens exactly when your trying to run the program?

Other than that, I'd try getting another compiler.


----------



## JMPC (Jan 15, 2011)

Microsoft has "express" versions of Visual Studio that are free if you wanted to go with something else.


----------



## shuuhen (Sep 4, 2004)

PC person said:


> I go it's directory, after typing cmd.exe in run, which is C:\prog and type gcc dumb.c -o dumb, and I get
> 
> gcc: dumb.c: No such file or directory
> gcc: no input files
> ...


Have you checked the output of the *dir* command? Make sure dumb.c is there.



PC person said:


> I'm told I have to leave a blank line after the second bracket (does it matter how many?)


The C standard says you need a file to end with a newline, which means you should have at least one blank line at the end of your source files. More than one should be fine, but you only need one. The C++ standard also specifies that a file should end in a newline.


----------



## PC person (Feb 2, 2006)

shuuhen said:


> Have you checked the output of the *dir* command? Make sure dumb.c is there.
> 
> 
> The C standard says you need a file to end with a newline, which means you should have at least one blank line at the end of your source files. More than one should be fine, but you only need one. The C++ standard also specifies that a file should end in a newline.


I went ahead and reinstalled MinGW. Took a while, had several errors trying to download the update it asked me if I wanted to download the latest repository catalogs, I said yes, installed every option that MinGW gave me. Typed the same source code again, and got the same message.

the directory I'm keeping my source code (C files) in is C:\prog. Under Windows it tells me that are two files there, after I clck save as, and save it as a C file. They are dumb and .dumb. Under cmd,exe, "dos" it tells me I have 61 dumb, and three dir "files" and a file folder called C.

It seems it knows what I"m trying to do, it just can't do it for some reason, at least I don't get "Bad command or file name"


----------



## Ninjaboi (Dec 27, 2010)

.dumb
^

That period might be your problem, as it says "Bad command or *file name*". I'd suggest trying to switch the name to something else like 'dumb1' or 'dumbdumb' and see if compiling won't be an issue anymore.


----------



## PC person (Feb 2, 2006)

Ninjaboi said:


> .dumb
> ^
> 
> That period might be your problem, as it says "Bad command or *file name*". I'd suggest trying to switch the name to something else like 'dumb1' or 'dumbdumb' and see if compiling won't be an issue anymore.


No, I said I am not getting bad command or file name. Actually, what is cmd.exe? I know that it was one of the three components of DOS- command.com along with io.sys and one other file. I know config.sys was about drivers and autoexec.bat was optional. It certainly appears to be DOS, but I know it isn't truly. Anyway, I tried typing some random characters, and I don't get bad command or file name. I get:

"whateverItypegoeshere" is not recognized as an internal or external command operable program or batch file.

I don't know why it's creating 2 files. I click the file menu in Gvim easy 7.2, save as file type C source (*c,*h), in that directory I specified. Actually, maybe I do, will it create a *c files and whatever an *h is?


----------



## Ninjaboi (Dec 27, 2010)

Ah, in that case try going to this link:

'File name' is not recognized as an internal or external command, operable program or batch file?

The person who made that thread had the same problem, and his problem was solved.


----------



## PC person (Feb 2, 2006)

Ninjaboi said:


> Ah, in that case try going to this link:
> 
> 'File name' is not recognized as an internal or external command, operable program or batch file?
> 
> The person who made that thread had the same problem, and his problem was solved.


But, I don't get that error (is not recognized as an internal of external command) when I try to compile it, I get the error I posted above.


----------



## Ninjaboi (Dec 27, 2010)

> gcc: dumb.c: No such file or directory
> gcc: no input files


Try creating a new project with the name "Hello World". Ensure this is a console project if you need to declare it. Follow this up by creating a '.c' file named "hello", which would be "hello.c". For the code that will be inside "hello.c", try putting this code inside:


```
#include <iostream>

int main()
{

     printf("Hello World!");
     return 0;

}
```
After you've entered that code inside "hello.c", compile and execute the code. Inform us if that works, or if not tell us if you get similar or different compile errors as you've had before.


----------

