Getting started with C on my Linux machine.

Discussion in 'C Programming' started by ThaDoctor, Jul 26, 2006.

  1. ThaDoctor

    ThaDoctor Guest

    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
    ThaDoctor, Jul 26, 2006
    #1
    1. Advertising

  2. ThaDoctor

    pete Guest

    ThaDoctor wrote:
    >
    > 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.

    --
    pete
    pete, Jul 26, 2006
    #2
    1. Advertising

  3. ThaDoctor

    ThaDoctor Guest

    pete skrev:

    > ThaDoctor wrote:
    > >
    > > 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.
    >
    > --
    > pete


    and after I have written and cmpiled how do I run the program under
    linux ?
    ThaDoctor, Jul 26, 2006
    #3
  4. ThaDoctor

    ThaDoctor Guest

    pete skrev:

    > ThaDoctor wrote:
    > >
    > > 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.
    >
    > --
    > pete


    And after this how do I run the program under linux ?
    ThaDoctor, Jul 26, 2006
    #4
  5. ThaDoctor <> wrote:

    > 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>

    --
    C. Benson Manica | I *should* know what I'm talking about - if I
    cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
    Christopher Benson-Manica, Jul 26, 2006
    #5
  6. ThaDoctor

    Bill Pursell Guest

    ThaDoctor wrote:
    > pete skrev:
    >
    > > ThaDoctor wrote:
    > > > 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.

    >
    > 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/
    Bill Pursell, Jul 26, 2006
    #6
  7. ThaDoctor

    cp Guest

    Go to the place where you "saved" the compiled file and write: ./<program>
    That is: dotSLASH<program-name>
    cp, Jul 26, 2006
    #7
  8. ThaDoctor

    Chris Dollin Guest

    ThaDoctor wrote:

    >
    > pete skrev:
    >
    >> ThaDoctor wrote:
    >> >
    >> > 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.
    >>
    >> --
    >> pete

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

    --
    Chris "programPathOrNameAlongPath RETURN" Dollin
    A rock is not a fact. A rock is a rock.
    Chris Dollin, Jul 27, 2006
    #8
  9. ThaDoctor

    Guest

    Chris Dollin wrote:
    > ThaDoctor wrote:
    >
    > >
    > > pete skrev:
    > >
    > >> ThaDoctor wrote:
    > >> >
    > >> > 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.
    > >>
    > >> --
    > >> pete

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


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

    >
    > --
    > Chris "programPathOrNameAlongPath RETURN" Dollin
    > A rock is not a fact. A rock is a rock.
    , Jul 27, 2006
    #9
  10. ThaDoctor

    Chris Dollin Guest

    wrote:

    >
    > Chris Dollin wrote:
    >> ThaDoctor wrote:
    >>
    >> >
    >> > pete skrev:
    >> >
    >> >> ThaDoctor wrote:
    >> >> >
    >> >> > 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.
    >> >>
    >> >> --
    >> >> pete
    >> >
    >> > 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.

    >
    > 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."

    --
    Chris "finder" Dollin
    "The path to the web becomes deeper and wider" - October Project
    Chris Dollin, Jul 27, 2006
    #10
  11. ThaDoctor

    Guest

    wrote:

    > Chris Dollin wrote:
    > > ThaDoctor wrote:
    > >
    > > >
    > > > pete skrev:
    > > >
    > > >> ThaDoctor wrote:
    > > >> >
    > > >> > 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.
    > > >>
    > > >> --
    > > >> pete
    > > >
    > > > 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.

    >
    > 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.
    }

    Christopher Benson-Manica wrote:

    > ThaDoctor <> wrote:
    >
    > > 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>


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


    Bill Pursell wrote:

    > ThaDoctor wrote:
    > > pete skrev:
    > >
    > > > ThaDoctor wrote:
    > > > > 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.

    > >
    > > 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


    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
    , Jul 27, 2006
    #11
  12. ThaDoctor

    Guest

    wrote:
    > wrote:
    >
    > > Chris Dollin wrote:
    > > > ThaDoctor wrote:
    > > >
    > > > >
    > > > > pete skrev:
    > > > >
    > > > >> ThaDoctor wrote:
    > > > >> >
    > > > >> > 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.
    > > > >>
    > > > >> --
    > > > >> pete
    > > > >
    > > > > 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.

    > >
    > > 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


    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 "./"?

    > 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.
    > }
    >
    > Christopher Benson-Manica wrote:
    >
    > > ThaDoctor <> wrote:
    > >
    > > > 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>

    >
    > I don't think that a beginner will get much out of the gcc man page.
    >
    >
    > Bill Pursell wrote:
    >
    > > ThaDoctor wrote:
    > > > pete skrev:
    > > >
    > > > > ThaDoctor wrote:
    > > > > > 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.
    > > >
    > > > 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

    >
    > 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
    , Jul 27, 2006
    #12
  13. On 27 Jul 2006 10:29:04 -0700, "" <>
    wrote:

    >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
    Clifford Stern, Aug 1, 2006
    #13
  14. ThaDoctor

    Guest

    Clifford Stern wrote:
    > On 27 Jul 2006 10:29:04 -0700, "" <>
    > wrote:
    >
    > >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,


    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.

    >
    > Clifford Stern
    >
    , Aug 1, 2006
    #14
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    5
    Views:
    524
    Roedy Green
    Oct 25, 2005
  2. Dr. Laurence Leff
    Replies:
    3
    Views:
    505
    Christopher Cooper
    Aug 17, 2003
  3. Jake Barnes
    Replies:
    2
    Views:
    288
  4. Andrew Berg
    Replies:
    0
    Views:
    151
    Andrew Berg
    Oct 4, 2012
  5. Dennis Lee Bieber
    Replies:
    0
    Views:
    151
    Dennis Lee Bieber
    Oct 5, 2012
Loading...

Share This Page