Getting started with C on my Linux machine.

T

ThaDoctor

I would like to get started with programming in C, but I cant get it to
work, I do not need any compiler or such.
Only a basic explanation of the first program Hello World that print
"Hello World" on the screen.

Greetings Tobias
 
P

pete

ThaDoctor said:
I would like to get started with programming in C,
but I cant get it to
work, I do not need any compiler or such.
Only a basic explanation of the first program Hello World that print
"Hello World" on the screen.

The whole point of the Hello World program,
is to gain enough familiarity with your C implementation
to write, translate, and execute a C program.
 
T

ThaDoctor

pete skrev:
The whole point of the Hello World program,
is to gain enough familiarity with your C implementation
to write, translate, and execute a C program.

and after I have written and cmpiled how do I run the program under
linux ?
 
T

ThaDoctor

pete skrev:
The whole point of the Hello World program,
is to gain enough familiarity with your C implementation
to write, translate, and execute a C program.

And after this how do I run the program under linux ?
 
C

Christopher Benson-Manica

ThaDoctor said:
and after I have written and cmpiled how do I run the program under
linux ?

<ot>
Run a.out. man gcc for details, assuming that's your compiler.
Take further questions to comp.unix.programmer.
</ot>
 
B

Bill Pursell

ThaDoctor said:
pete skrev:


and after I have written and cmpiled how do I run the program under
linux ?

% gcc hello_world.c -o hi # compile the program
% ./hi # execute the program

In the above, '%' represents your command prompt.
Your questions are not really appropriate in this
newsgroup, but once you've figured out the basics
and have questions about the C language, those
questions will probably be topical. Make sure
to read the faq:

http://www.c-faq.com/
 
C

cp

Go to the place where you "saved" the compiled file and write: ./<program>
That is: dotSLASH<program-name>
 
C

Chris Dollin

ThaDoctor said:
pete skrev:


And after this how do I run the program under linux ?

The same way you run any other program in Linux, which, if
you ran the compiler, you presumably already know.
 
M

mensanator

Chris said:
The same way you run any other program in Linux, which, if
you ran the compiler, you presumably already know.

How does it follow from running the compiler by invoking
"gcc hello.c" that one runs the program by typing "./a.out"?
 
C

Chris Dollin

How does it follow from running the compiler by invoking
"gcc hello.c" that one runs the program by typing "./a.out"?

Because in both cases -- more than both, since the OP presumably
knows more Linux commands than just `gcc` -- one types an
abbreviated version of the program's name.

The /real/ answer to the OPs question is, I suppose, "Usenet
is not, and is not intended to be, a substitute for an
actual person bootstrapping you."
 
S

spibou

How does it follow from running the compiler by invoking
"gcc hello.c" that one runs the program by typing "./a.out"?

umteenth_out_of_topic_post {

Because the compiler as a default will create an executable
with name a.out (derived from "assembler output") in your
working directory. In Unix a single dot (.) is shorthand for
your working directory. So typing "./a.out" (without the quotes)
tells to the operating system to execute the file in the working
directory with name a.out Of course such a file will be created
only if the compilation completed without poblems.

If dot (.) appears in your PATH variable then you can simply type
a.out If you didn't understand the last sentence you can safely
ignore it.
}
<ot>
Run a.out. man gcc for details, assuming that's your compiler.
Take further questions to comp.unix.programmer.
</ot>

I don't think that a beginner will get much out of the gcc man page.


Bill said:
% gcc hello_world.c -o hi # compile the program
% ./hi # execute the program

There is a pitfall here in that if there's already a file with name
"hi",
then the compilation command will silently overwrite it.

Spiros Bousbouras
 
M

mensanator

umteenth_out_of_topic_post {

Because the compiler as a default will create an executable
with name a.out

But because it is a default, there is no reason to assume that
a new user would know that. If the syntax of the compiler forced
you to specify a destination file, such as "gcc hello.c a.out",
then it would follow that the user would know what the output
file is because he had to type it. When defaults are involved,
it does not follow that a user knows how to run the program
since he knew how to run the compiler.
(derived from "assembler output") in your
working directory. In Unix a single dot (.) is shorthand for
your working directory. So typing "./a.out" (without the quotes)
tells to the operating system to execute the file in the working
directory with name a.out

That wasn't what I was asking. I asked how does knowing how
to run the compiler without the leading "./" infer that one must
preceed a.out with "./"?
 
C

Clifford Stern

That wasn't what I was asking. I asked how does knowing how
to run the compiler without the leading "./" infer that one must
preceed a.out with "./"?

This isn't a compiler issue, it's a matter of whether the current
directory is in the PATH variable. When I want a program to execute
without the leading "./", I move it to /usr/local/bin.

Clifford Stern
(e-mail address removed)
 
M

mensanator

Clifford said:
This isn't a compiler issue,

I didn't say it was.
it's a matter of whether the current
directory is in the PATH variable.

I didn't ask why it works the way it does.
When I want a program to execute
without the leading "./", I move it to /usr/local/bin.

No one asked what you want. The question was

"How does knowing how to run the compiler infer that
one knows how to run the program?"

Please try to keep up.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top