Insufficient information. For example, what operating system are you using? By your terminology, I would assume Linux. And just what exactly are you doing when you try to run the program? You are forcing us to make assumptions and wild guesses.

By "running the program in terminal", this is what I'm assuming:

What you display here is not the entire program. I assume that you did #include the header file for printf, stdio.h .

You have opened the terminal (AKA "DOS window" or "Command Prompt" in Windows) and have navigated to the directory where the executable file (.exe in Windows) resides.

You run the executable from the command line.

If those assumptions are wrong, then you need to tell us what's really happening.

For example, if you are using Windows and your development environment ("integrated development environment" (IDE) that combines editor, compiler, linker, debugger, project manager, and other functionalities, commonly mis-named "my compiler") is a GUI app and you are running your program from the GUI, then your problem is very well-known and is due to trying to run a console app in a manner that it was not intended to be run. In that situation, the OS creates a console (the technical Windows term for "DOS window") for your program to run in. Then when your program terminates normally, that console automatically closes. What you need to do in that case is to keep the console from closing until you tell it to. A common kludge is to make an input function (eg, getchar()) the last line.

Besides having left out the inclusion of stdio.h, you also failed to declare main's return type, which should be int, and the return 0; statement at the end to honor the function's return type.

PS

Most likely scenario is that you are using a GUI IDE on Windows.

However, if you are indeed trying to run it from the command line, then the problem is more subtle. Did you indeed neglect to #include stdio.h? If so, then the compiler wouldn't have known anything about printf and would have generated warnings about it (what did your warnings say?). I've seen compilers still be able to link to the standard C library function in such situations, while I've also seen some not be able to do that and cause "weird problems". So then if you are indeed running from the command line (as God had intended this type of program to be run) and you did indeed neglect to #include stdio.h, and you do not get any output when you run that program, then #include that header file and see whether that fixes it.

Whatever happens, when you have a problem that you need help with, then you do need to tell us exactly what you are doing. Working from sufficient information is far better than having to make wild guesses, plus you get your answer much quicker.

Also, do not ignore warnings! Getting warnings means that there's something very questionable about your code, namely that it's broken in some way. Even if a compiler generates an executable, if you're getting warnings then you have no quarantee that that executable is going to do what you expect it to do. Too many IDEs turn warnings off by default. Always turn warnings on and up! Warnings are far more important than error messages. Never ignore warnings.

If by Terminal you mean OS X's Terminal, you need to make sure you install Xcode and the Xconde command-line utilities. Then you should be able to use make or raw gcc. If your program file is test.c, then typing

Code:

make test

in the terminal will yield an executable file in the same directory; for raw gcc you would type

Code:

gcc -o test test.c

to get the same result.

I ♥ ManiacDan & requinix

This is a sig, and not necessarily a comment on the OP:Please don't be a help vampire!

Beginner C - Running C in Terminal complete with more information.

Alright so I am using linux via my mac which operates on Mac OS Yosemite 10.10. As to what exactly I am trying to do. Currently I am working through the first example in The C-programming book by Brian Kernighan and Dennis Ritchie.
As to what I am expecting to happen. When I call the file(I have named this file hello.c), I expect to see "hello, world" printed in the command line. I appreciate all the help. I am knew to devshed so do not hesitate educate me on proper forum etiquette. Again thanks for the offering a your expertise.

Show us the code listing for your entire program. The warning on line 5 ("warning: type specifier missing, defaults to 'int'") tells me that you failed to #include stdio.h at the top of your code, which pulls in the function prototype for printf and would therefore inform the editor of that function and what its format is. That line of code would be:

Code:

#include <stdio.h>

As I had already said.

Also, look at main:

Code:

main()
(
printf("hello, world\n")
)

In C, every statement ends with the statement terminator, ; (semicolon). You left that out, so the compiler assumed that you were trying to create a new function inside of main, which is also why you got the first error because "hello, world\n" is not a valid parameter declaration (read the error message to verify that that is indeed what the compiler is complaining about).

Give that poor statement the semicolon termination that it needs. And #include stdio.h. Then report your progress. I have absolutely no programming experience on a Mac, so I don't know how it handles launching a console program from a GUI. Re-read my description of what happens when you do that under Windows for a possible clue in case it still "doesn't work" ("Oh, it works just fine! It did exactly what you told it to do! Too bad that's not the same thing as what you wanted it to do.").

Also, K&R are literally "old school", since they had literally created the language and the first edition of that book was the de facto reference manual for C. It's a good book and well worth having and using, but their writing style is out-of-date and deprecated in places.

They use the old C feature of allowing you to use functions and variables that you haven't declared; the compiler just assumes that they are all int (functions default to having one int parameter and returning int). That is bad practice and should be avoided at all times; always declare all variables and functions before you use them. Instead, main should be declared on one of two ways:

Code:

int main()
{
return 0;
}

or

Code:

void main()
{
}

Declaring main() as int and returning zero is very much preferred, since your program is expected to return an exit code to the process that had launched it -- returning zero means it ran successfully while returning a positive non-zero means that it terminated abnormally because of some kind of error (you choose arbitrarily what failure code to use for what type of error, eg a 2 for "file not found").

So after following your instructions, I revised my code. Included a header, changed to main to int main, declared 0. I assigned a variable to prinf(), then assigned a function to c to get the characters, and display those characters. However, I am still receiving some errors.

What did you use to write your code? A text editor or a word processor? You used a word processor, didn't you? A word processor will "do you a big favor" and give you real purdy open and close quotes: 0x93 and 0x94 respectively. Those are extended ASCII codes, which means that they are greater than the regular 7-bit ASCII codes (max code is 127) which are standard; extended codes are not standard. Only the standard 7-bit codes are recognized by the compiler. For the double quote, it expects 0x22.

I know that the Mac has a text editor hidden away somewhere. I was very surprised when I found it. Look for that text editor and use it for all your coding. Or you could use a Linux text editor instead if you are able to. Just stay completely away from word processors when you write code.