Hello!
So this is pathetically easy as programs go in the C language (i hope).

I am working on a variation of the Hello World program (as I am just starting to learn C, solo).
I am using the C All-in-One for dummies book, and I got a little ways into it about a year or more ago, but stopped due to school studies. Anyway, I'm finding a little more time to tackle it again, and it's driving me banana sandwiches!

I can't get it to display the text in the windows command line (cmd.exe).

#include <stdio.h>

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

I am using the vim text editor (www.vim.org), as before, and Bloodshed Dev C++ for my compiler, & running the program in cmd.exe (windows 7 pro 64 bit).

I know the program is working (sorta) because it doesn't give me any error message.

the author guides you in configuring/setting up your compiler and everything he has told me works. It is only when I run this program... I run it and no error message. simply a small pause with no texts showing and it goes back to the directory, awaiting my next command. I started to look on google to see if the puts function was just the wrong function to use, but it's already 230am..lol and i've had it working before on the same machine, but on the Home Premium version of windows 7 64 bit.

any suggestions on where I can start to troubleshoot this?

Recommended Answers

All 10 Replies

Try using printf("Greetings, human!"); (just a guess, honestly)

How are you getting your code from Vim to the IDE? (in other words are you opening a project for it..or?) If you're writing in Vim, you could just possibly skip the IDE and compile right from the command line.

There's nothing wrong with your code - runs fine. There are some good C IDE's (integrated development environments), with editors, help buttons, and messages from the compiler and linker, and debugger.

Visual Express from Microsoft is one, and Code::Blocks is very good, as well, although it's separate from the compiler. Why not Google one up and give it a shot? Bound to be more productive.

Try using printf("Greetings, human!"); (just a guess, honestly)

That's subtly different because you didn't include a newline at the end. While printf is the function you'll see most in hello world programs, puts works just fine.

How are you getting your code from Vim to the IDE? (in other words are you opening a project for it..or?) If you're writing in Vim, you could just possibly skip the IDE and compile right from the command line.

Hey, thanks for responding. I'll try to explain what I do as best I can. Using vim, I write the program. I then proceed to save as a .c file, in this case, dumb.c

From that point, I go to the command line and after making sure I'm in the correct directory, i type "gcc dumb.c -o dumb" (no quotations obviously) and that's how i run the program.

I had downloaded Bloodshed Dev-C++, which I assume in this case is.. my compiler? I'm still trying to understand this part better. As instructed in the book I'm using, I went into the System Properties window, clicked the Environment Variables and edited the Path variable to:

C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Live\Shared;C:\Dev-Cpp\bin

I only edited the end C:\Dev-Cpp\bin

Does that help? Thanks for your quick response everyone!

hi there,

Try a simple thing, use a getchar(); after puts("");

#include <stdio.h>

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

In case this doesn't work do it like this,
Use vim to save your source file in C:\Dev-Cpp\bin
Then go to the directory using command prompt and then provide your

gcc dumb.c -o dumb

command.
This will generate the executable "dumb" if there are no errors.
Now run the executable by simply typing the name and pressing enter.
You should see the text you wanted to display.

If not tell me what you do see in the command window while compiling and running the program.


Anirudh

hi there,

Try a simple thing, use a getchar(); after puts("");

#include <stdio.h>

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

In case this doesn't work do it like this,
Use vim to save your source file in C:\Dev-Cpp\bin
Then go to the directory using command prompt and then provide your

gcc dumb.c -o dumb

command.
This will generate the executable "dumb" if there are no errors.
Now run the executable by simply typing the name and pressing enter.
You should see the text you wanted to display.

If not tell me what you do see in the command window while compiling and running the program.


Anirudh

My only question with this action is this: before I had a set up a series of folders (per the book) and it worked just fine running my source code. I took a look inside the bin folder you mentioned and there are quite a few things in there. if this idea did work, why would it work there and not in, say: C:\...\My Documents\prog\c\basic ?

I hate to be picky, especially since i'm asking for help, but i know it worked before with this setup.

try

#include <stdio.h>

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

it works with gcc

Stop trying to fix his code! It's correct.

The problem is your terminology. You said

From that point, I go to the command line and after making sure I'm in the correct directory, i type "gcc dumb.c -o dumb" (no quotations obviously) and that's how i run the program.

That command only runs the compiler, not the program. You don't have a program yet.

Once compiled (and linked for those here who are anal about it) you still have to run the program. See the last part of anirudh33's post.


Also,

I know the program is working (sorta) because it doesn't give me any error message.

That's no guarantee it's working. It only means it compiled. Your syntax is all correct. But the program can still be wrong.

#include <stdio.h>
int main()
{
    int v;
    v = 2+3*5;
    printf("2+3 multiplied by 5 = %d\n", v);
    return 0;
}

This code works using your definition (no compile errors) but it's still wrong.
Why? :icon_wink:

My only question with this action is this: before I had a set up a series of folders (per the book) and it worked just fine running my source code. I took a look inside the bin folder you mentioned and there are quite a few things in there. if this idea did work, why would it work there and not in, say: C:\...\My Documents\prog\c\basic ?

I hate to be picky, especially since i'm asking for help, but i know it worked before with this setup.

hello again

You should try first what I told you, if that works fine, then I will be a bit more sure and come to a conclusion about what was wrong and will be able to tell you why it isn't working in the specific directories you have created.

Also tell me the exact output on command line as seen by you while compiling and executing the program in the directories you specified.

Anirudh

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.