Thread: Brand New to C - How to Compile if file on desktop?

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    26

    Brand New to C - How to Compile if file on desktop?

    I am learning c programming, please excuse english + knowledge in c. Tutorial says:

    "Type this program into a file and save it as add.c. Compile it with the line gcc add.c -o add and then run it by typing add (or ./add)."

    I am using mac, file 'add.c' on my desktop. I am using Terminal to type in the above command line. How do I specify where to pull the file?

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    You'll need to make sure the Terminal is using the Desktop as the working directory already, or specify a more specific path. Assuming that the Desktop is subfolder in the home folder ( that's the way it is with Linux - I haven't done this on a mac ), you have two options:

    Code:
    cd Desktop
    
    gcc add.c -o add
    
    ./add
    or

    Code:
    gcc Desktop/add.c -o Desktop/add
    
    Desktop/add
    Again - I haven't done much programming on a mac, I don't know if these commands are the same, but they are standard for UNIX, so my guess is they are.

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    26
    Quote Originally Posted by sean View Post
    Code:
    gcc Desktop/add.c -o Desktop/add
    
    Desktop/add
    Worked perfectly. What command do I enter to end my program?

  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by zacharyrs View Post
    Worked perfectly. What command do I enter to end my program?
    There is a big button for this on the front panel.

    Just kidding. Try "ctrl-c" or "ctrl-z". Really, your program should just end when it is finished, but without seeing it I can't say for sure.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    26
    Ah yes, thank you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  2. To find the memory leaks without using any tools
    By asadullah in forum C Programming
    Replies: 2
    Last Post: 05-12-2008, 07:54 AM
  3. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  4. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  5. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM