Thread: Help Opening C Program from Mac Terminal

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    2

    Help Opening C Program from Mac Terminal

    Hello,

    I'm required to run some C Programs for my C Programming class in Terminal. I have never used Terminal before and can't seem to figure out how to do this.
    I'm using Xcode as my compiler. I figured out how to get Xcode to make an exe file of my program so that I can use it in Terminal. If I double click on the exe file on my computer, it will run in Terminal, but it does this before I can enter any strings for it to use.

    Can someone please guide me through the process of compiling and running the program in Terminal?

    Below is an example of what I'm typing in Terminal with no results. Repeat is the name of my program.

    John-Smiths-MacBook:desktop smith_j$ ls "/Users/smith_j/Desktop/C Programming Class/repeat 3-27-13 6.49 PM/usr/local/bin/"
    repeat
    John-Smiths-MacBook:desktop smith_j$ "repeat" resistance is futile
    -bash: repeat: command not found

    This is my program:
    #include <stdio.h>
    int main(int argc, char *argv[])
    {
    int count;

    printf("The command line has %d arguments:\n", argc - 1);
    for (count = 1; count < argc; count++)
    printf("%d: %s\n", count, argv[count]);
    printf("\n");

    return 0;
    }
    Last edited by sunworshipper; 03-28-2013 at 07:33 PM.

  2. #2
    young grasshopper jwroblewski44's Avatar
    Join Date
    May 2012
    Location
    Where the sidewalk ends
    Posts
    294
    Compiling a C program on Mac OS X - YouTube

    A little youtube video I quickly found. It uses gcc.

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    583
    Quote Originally Posted by sunworshipper View Post
    John-Smiths-MacBook:desktop smith_j$ ls "/Users/smith_j/Desktop/C Programming Class/repeat 3-27-13 6.49 PM/usr/local/bin/"
    repeat
    John-Smiths-MacBook:desktop smith_j$ "repeat" resistance is futile
    -bash: repeat: command not found
    Try:

    Code:
    "/Users/smith_j/Desktop/C Programming Class/repeat 3-27-13 6.49 PM/usr/local/bin/repeat" resistance is futile
    You can't just type "repeat" because the terminal doesn't know what you mean. It doesn't know there's a program called "repeat" somewhere deep in the file system.

    If you change into the directory:
    Code:
    cd "/Users/smith_j/Desktop/C Programming Class/repeat 3-27-13 6.49 PM/usr/local/bin"
    Then you can just run it with

    Code:
    ./repeat
    The reason you can type some executable names without specfiying where they are is usually because the directory is listed in the PATH environment variable. This is a list of places for the system to look for programs. You can change and add to PATH, but I wouldn't expect you to for a single test program like this. There's no rules saying you can't, but it'd be more hassle than just typing the location of your program.

    Apologies if this is all wrong -- I've never actually used a Mac

  4. #4
    Registered User
    Join Date
    Mar 2013
    Posts
    2
    Quote Originally Posted by smokeyangel View Post
    Try:

    Code:
    "/Users/smith_j/Desktop/C Programming Class/repeat 3-27-13 6.49 PM/usr/local/bin/repeat" resistance is futile

    Apologies if this is all wrong -- I've never actually used a Mac
    BIG THANK YOU!!!

    This worked.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 08-28-2011, 09:01 PM
  2. how to tell ncurses program terminal size
    By apawamajawa in forum Linux Programming
    Replies: 1
    Last Post: 07-20-2011, 02:04 AM
  3. Replies: 2
    Last Post: 02-11-2011, 04:45 AM
  4. program wont run on terminal services
    By bart21 in forum C# Programming
    Replies: 3
    Last Post: 11-25-2010, 12:26 PM
  5. Replies: 0
    Last Post: 11-30-2001, 01:52 PM

Tags for this Thread