2 Programs, 1 a.out How do I run the 1st program?

Discussion in 'Mac Programming' started by cybrscot, Dec 25, 2010.

  1. cybrscot macrumors 6502

    cybrscot

    Joined:
    Dec 7, 2010
    Location:
    Somewhere in Southeast Asia
    #1
    Okay

    I have written two simple programs, helloworld.c and merrychristmas.c

    Both compiled and executed okay, but my question is that in my documents folder I have both programs, but one a.out.

    So when I first did helloworld, I typed ./a.out then my program executed and said hello world.

    Then I compiled my second program (merrychristmas) and I typed ./a.out and it executed.

    My question/dilemma is when I type ./a.out, it seems to be executing my most recent program. if I recompile, I guess that's what I'm doing when I type gcc ~/Documents/merrychristmas.c then it will execute the program I'm recompiling.

    Do I need to re-compile as I showed in the above example every time to run the program I choose?

    Or is there another way to run the program within terminal, without entering gcc again?

    Thanks, and Merry Christmas to everybody out there!!
     
  2. dynetk macrumors newbie

    Joined:
    Mar 7, 2006
    Location:
    Sacramento, CA
    #2
    The a.out in the directory will always be the the program that you last compiled. So if you compiled helloworld.c last then that's what it will be. If you want to be able to run both of them without recompiling then you have a couple of options. You can either rename the a.out file after recompiling (mv a.out helloworld) or you can compile it with the output option (gcc helloworld.c -o helloworld).
     
  3. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #3
    In either case don't forget to run the program as ./helloworld or ./merrychristmas after using -o or renaming a.out. ;)

    B
     
  4. cybrscot thread starter macrumors 6502

    cybrscot

    Joined:
    Dec 7, 2010
    Location:
    Somewhere in Southeast Asia

Share This Page