Compile and run a program with Terminal

Hello, I used TextWrangler to create a .c file on my desktop. I want to compile and run the program using Terminal. However, I am new to programming and I am not sure how to achieve this. I have Xcode with Command Line Tools downloaded. I have the file "6_19.c" on my desktop currently. Any help would be appreciated.

Your Desktop probably isn't in your execution path, so you might want to start by moving "6_19.c" from your Desktop to your Home folder. After that, in Terminal, just do
gcc -o 6_19 6_19.c
The general format is
gcc -o <name you want the compiled program to have> <name of the source>.c
Do not put any .extension on the end of the name you want the compiled program to have. Also note that after "gcc" there's a space, then a dash and the next character is a lower case letter 'o', not a numerical zero. There's a space between the name of the compiled program and the name of the source.
To run the program, at your terminal prompt type
./6_19
The general format is dot forward slash <name of the compiled program>
There's no spaces at all.
Good luck.

Similar Messages

  • How to Set up the  variables and others to compile and Run Java Programs

    Hello,
    I have just downloaded the jdk1.6.0_07 and jre1.6.0_07 and installed it in C:\Program files\Java in my Windows XP ,So please tell me how to sett up the enviroment variables etc to compile and run Java Programs from Command Prompt.
    thanks

    To set the PATH permanently, add the full path of the jdk1.6.0_<version>\bin directory to the PATH variable. Typically this full path looks something like C:\Program Files\Java\jdk1.6.0_<version>\bin. Set the PATH as follows on Microsoft Windows:
    1. Click Start > Control Panel > System on Windows XP or Start > Settings > Control Panel > System on Windows 2000.
    2. Click Advanced > Environment Variables.
    3. Add the location of bin folder of JDK installation for PATH in User Variables and System Variables. A typical value for PATH is:
    C:\Program Files\Java\jdk1.6.0_<version>\bin

  • Compile and run java programs in different directroy

    Hi,
    I often encounter many problems when I run java programs in the different directories. Like
    javac -d dir_name a.java
    java -cp dir_name a
    Something wired often happens, such as, there is not a.java file in some directory, but javac -d dir_name a.java can still work or "java -cp dir_name a" often doesn't work. Moreover, file_name.jar is also a tough problem and solving compiling problems is often time-consuming.
    So I hope to read something about how to compile and run java programs in different directory properly.
    Could you pleae give me a detailed description for that or recommend a book or website?
    Thanks a lot.

    Can you post a small amount of code that does not work, including the directory structure, and the error messages? Some one here can likely explain the problem.

  • How to  compile and run javacard program

    how to compile and run javacard program "HelloWorld"

    1. Where is save Servlet program?
    2. How to set classpath?
    3. how compile and run?
    http://www.coreservlets.com

  • Compile and run java programs using batch file

    i am using eclipse to run my java programs.How to compile and run those programs using a batch file?

    a) just write a batch file, and add it to the project. When you want to run it, go to a command window and invoke it. (There is probably also a way to invoke it from Eclipse)
    b) if the project is complicated, take a look at ant. Eclispe knows about ant files.

  • How to compile and run package programs in Java

    Hi,
    I want to know how to compile and run the package programs in Java using -d. instead of creating the package folder manually.
    eg:
    package Test;
    class test1
    public void disp()
    //Any code;
    I want to compile this without creating the folder ' Test ' manually. that is if we use -d with javac the Test folder will be created automatically. I need the format of -d
    could anyone please help me.
    Thanks in Advance ,
    Ambika

    My program Test.java in F:\Tomcat5\webapps\Ambika\WEB-INF\Classes. I compiled in the format below. I got like this. What should I do for this? But yesterday I compiled like this only, It compiled and the folder com\cert\Test.class is created. Today again I compiled the pgm after deleting the already created folder 'com\cert', I got the error like this.
    I've given my pgm and the thing I've got when I compiled it.
    Test.java
    package com.cert;
    public class Test
         public void display()
              System.out.println("Hai");
    F:\Tomcat5\webapps\Ambika\WEB-INF\Classes>javac -d F:\Tomcat5\webapps\Ambika\WEB-INF\Classes\Test.java
    javac: no source files
    Usage: javac <options> <source files>
    where possible options include:
    -g Generate all debugging info
    -g:none Generate no debugging info
    -g:{lines,vars,source} Generate only some debugging info
    -nowarn Generate no warnings
    -verbose Output messages about what the compiler is doing
    -deprecation Output source locations where deprecated APIs are u
    sed
    -classpath <path> Specify where to find user class files
    -cp <path> Specify where to find user class files
    -sourcepath <path> Specify where to find input source files
    -bootclasspath <path> Override location of bootstrap class files
    -extdirs <dirs> Override location of installed extensions
    -endorseddirs <dirs> Override location of endorsed standards path
    -d <directory> Specify where to place generated class files
    -encoding <encoding> Specify character encoding used by source files
    -source <release> Provide source compatibility with specified release
    -target <release> Generate class files for specific VM version
    -version Version information
    -help Print a synopsis of standard options
    -X Print a synopsis of nonstandard options
    -J<flag> Pass <flag> directly to the runtime system
    F:\Tomcat5\webapps\Ambika\WEB-INF\Classes>
    Plz help me.
    thanks in advance
    Ambika

  • How to compile and run java program at command console

    hi there
    can anyone tell me how to compile and run a java program at command console? I have installed JRE 1.3.1, and also have installed JBuilder 5 if it helps.

    try this
    System.out.println("Enter your Name : ");
    BufferedReader console = new BufferedReader( new InputStreamReader( System.in ) );
    String s = console.readLine();
    System.out.println("Hello : "+ s+" !" );

  • How to compile and Run servlet Program

    Hi,
    pls help me the following doubt
    i am using Tomacat 4.1 server.
    1. Where is save Servlet program?
    2. How to set classpath?
    3. how compile and run?
    bye
    Mathi

    1. Where is save Servlet program?
    2. How to set classpath?
    3. how compile and run?
    http://www.coreservlets.com

  • How do I compile and run Java programs on a Mac?

    To clarify my earlier post, I know that you can write java in any text editor but with the PC you compile and run everything through the MS DOS prompt, what is the Mac equivalent?

    See this question :-)
    http://forum.java.sun.com/thread.jsp?forum=54&thread=289574

  • How do I write and run c++ programs via terminal?

    First off, if this is the wrong place to post, my apologies. I'm running arch off a raspberry pi, and sshing into it on my computer (a mac, if it makes a difference), and I was wondering how I could run c++ programs on it. I don't want to install a desktop environment, because I think using terminal is a cool challenge. I'm assuming I can just use nano or some other text editor to write them, but how do I get them to run, as well as get all the libraries I would need? I am thinking just things that run in terminal, no programs with a gui. Any suggestions?

    First, I am going to suggest you take Arch Arm questions to their forums.    They are the experts.
    But, what you ask is easy -- if the tools are installed on your ras-pi.  Here is some code I did not write that generates data that can be piped to gnuplot to animate a Lorenz  attractor. 
    ewaller$@$odin ~/devel/C/lorenz [130]1026 %cat lorenz.cpp
    #include <iostream>
    #define tab "\t"
    using namespace std;
    void lorenz(double *x,double *dxdt)
    dxdt[0]=10.0*(x[1]-x[0]);
    dxdt[1]=28.0*x[0]-x[1]-x[0]*x[2];
    dxdt[2]=-2.666666666666*x[2]+x[0]*x[1];
    int main(int argc,char **argv)
    int len=300;
    double x[len*3],dxdt[3],dt=0.01;
    x[0]=1.0;x[1]=1.0;x[2]=1.0;
    int cur=0,next=1;
    for(int i=1;i<len*10;i++)
    lorenz(x+3*cur,dxdt);
    for(int j=0;j<3;j++) x[3*next+j]=x[3*cur+j]+dt*dxdt[j];
    if(++cur == len) cur=0;
    if(++next == len) next=0;
    for(double t=0.0;t<100000000.0;t+=dt)
    cout<<"sp [-30:30][-30:30][0:50] '-' w l"<<endl;
    for(int i=cur+1;i<len;i++)
    cout<<tab<<x[3*i]<<tab<<x[3*i+1]<<tab<<x[3*i+2]<<endl;
    for(int i=0;i<cur+1;i++)
    cout<<tab<<x[3*i]<<tab<<x[3*i+1]<<tab<<x[3*i+2]<<endl;
    cout<<'e'<<endl;
    lorenz(x+3*cur,dxdt);
    for(int j=0;j<3;j++) x[3*next+j]=x[3*cur+j]+dt*dxdt[j];
    if(++cur == len) cur=0;
    if(++next == len) next=0;
    return 0;
    ewaller$@$odin ~/devel/C/lorenz 1027 %g++ lorenz.cpp
    ewaller$@$odin ~/devel/C/lorenz 1028 %./a.out|head
    sp [-30:30][-30:30][0:50] '-' w l
    -9.3252 -8.45882 29.0952
    -9.23857 -8.27211 29.1081
    -9.14192 -8.08701 29.0961
    -9.03643 -7.90593 29.0595
    -8.92338 -7.73113 28.999
    -8.80415 -7.56467 28.9156
    -8.68021 -7.40841 28.8105
    -8.55303 -7.26397 28.6853
    -8.42412 -7.13271 28.5417
    ewaller$@$odin ~/devel/C/lorenz 1029 %
    You may want to set up a cross compiler on your x86_64 Arch system for ARM.  That we can help you with....

  • Compiling and Running Swing Programs - can't execute tutorial

    Hi,
    Help is appreciated! :)
    I'm new to java and I'm following [this tutorial|http://java.sun.com/docs/books/tutorial/uiswing/start/compile.html] (I've pasted the code below after the error message.)
    I'm on Opensuse 11 / KDE4. Here's my output for java -version
    java version "1.6.0_06"
    Java(TM) SE Runtime Environment (build 1.6.0_06-b02)
    Java HotSpot(TM) Server VM (build 10.0-b22, mixed mode)
    I pasted the code in an editor, saved it in a temp directory as HelloWorldSwing.java
    In the console at the temp directory, I compiled without problems with "javac HelloWorldSwing.java"
    Two .class files are generated, HelloWorldSwing$1.class & HelloWorldSwing.class
    The tutorial says I can then run the app with "java HelloWorldSwing", but I get the following error.
    Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldSwing (wrong name: start/HelloWorldSwing)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
    package start;
    * HelloWorldSwing.java requires no other files.
    *import javax.swing.*;       
    public class HelloWorldSwing {
         * Create the GUI and show it.  For thread safety,
         * this method should be invoked from the
         * event-dispatching thread.
        private static void createAndShowGUI() {
            //Create and set up the window.
            JFrame frame = new JFrame("HelloWorldSwing");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            //Add the ubiquitous "Hello World" label.
            JLabel label = new JLabel("Hello World");
            frame.getContentPane().add(label);
            //Display the window.
            frame.pack();
            frame.setVisible(true);
        public static void main(String[] args) {
            //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
    }

    stringchopper wrote:
    I have to execute the file from a parent (project) directory all the time? if the class files are in /temp/start/ , I have to be in /temp and type:
    java start/HelloWorldSwing
    Well, you have to give the fully qualified CLASS NAME. Since your class is in a package named start, you have to specify start/HelloWorldSwing because that is your class' fully qualified name. Java has to manage class namespace and this is part of scheme. Also, while Java can use / or . as the package name separator character, it seems common that people use the period (start.HelloWorldSwing). In my view, this heps re-enforce the fact that it is a class name, not a file path.
    And, I have to have a directory named literally for my package name ("start"... "blah" won't work).
    Yes. Just like you can have different files with the same name in different directories, you can have different classes with the same name in different packages. And just like you can not have files with the same name in the same directory, you can not have the same class name in the same package.
    Why would the tut indicated running from the package directory? Perhaps something else isn't right on my system(?)
    If there is no system Classpath set, the current directory is the default Classpath.
    From the command line, it is common to use the -cp switch.java -cp /usr/myclasses mypackage.MyClass
    The link provided mentioned "echo $CLASSPATH"... mine came up empty. I've previously installed JDK and Netbeans - should I be concerned about how Netbeans will work if I set up a CLASSPATH system var?I can't help you with Netbeans but I believe most IDEs use their own method to find classes.

  • Using different JREs to compile and run JNI program

    Hi,
    Is it possible to use a JRE to compile a JNI program and then use another JRE to run it? For example, I'm compiling my program linking with Sun's libjvm.so and libjava.so. But at run time, I'll change my LD_LIBRARY_PATH to point to IBM's libjvm.so and libjava.so. Would it work at all?

    Oh I forgot to mentioned that I'm trying to invoke JVM in a C program to execute pre-compiled java byte code. (my bad... should've made that clear) So when I say "compile", I mean to compile C files instead of java files. So my original question is: is it possible to compile a C program invoking JVM linking with java and jvm libraries from vendor A and then at runtime, swapping java and jvm libraries with the ones from vendor B? (Since libjava.so and libjvm.so are dynamic libraries, it should work. But I was just making sure...) After some testing, I was able to compile my C program linking with Sun's libraries and to run it with IBM's libraries.

  • Compiling and running Java programs on my laptop

    I have just bought a new laptop but I can't run and compile Java programs using the javac filename.java command in the command prompt. I know I have to download something but I am not sure what link. I would be grateful if somebody could send me on a URL. My O/S is Windows XP. Can somebody advise please?

    If you just want to run java applications, you just need the JRE: J2SE 5.0 JRE
    If you want to compile java source code, you need the JDK: J2SE 5.0 JDK
    It includes also the JRE. Recommended is also the J2SE 5.0 Documentation that contains the javadoc API that describes all the Java classes.
    To start develeoping I recommend the Java Tutorial: http://java.sun.com/docs/books/tutorial/

  • How to develope, compile  and run soap service

    we want to implement the soap sevice in our concern.So its very diffcult to develope the soap program.I dont know about the soap service.please give me a input about soap and how to develope soap programs.Pls also give some sample programs and how to compile and run those programs.In our concern we are using UNIX operating system.
    Thanking you
    Yours faithfully
    Saran

    You should start by posting questions regarding web services on the correct forum ;)
    Next go to xml.apache.org and read the documentation regarding Apache Axis.
    You could also take a look at the Spring Framework's support for web services.
    You could even take a look at the Sun Web Service tutorials.
    The above resources have plenty of examples and sample code.

  • [HELP] When compiling and running, two consoles appear!

    When I compile and run a program, 2 consoles show up.. This wasn't happening before. I'm confused.
    After around 15 seconds, the lower window closes and the program starts.
    Here's a picture:
    http://i.imgur.com/iiqVvEr.png

    Hi Narralol,
    Sorry for late.
    I have never reproduced this. Please try to clean & build a master application that runs and positions your test application.
    I doubt that you may process start cmd window before you run this console app. Please try and to see if it exists.
    Have a nice day!
    Kristin
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

Maybe you are looking for

  • Missing /metadata/iam-features-ldap-sync in v11.1.1.6  OIM/OID sync

    Hi All Have picked up support of a site with Oracle Identity Management Suite already installed and need to create custom Schema attributes for users. Have modified the create user form no problem in OIM, and also created a custom class with the requ

  • Cause and effect in iPhoto

    What would cause my photo library of several thousand images to suddenly go blank and become an unrecognizable format? When I highlight a blank "place-saver", the information block says it is a JPEG Image. I have several other libraries which have no

  • How do i make it so when i type a url...

    it doesn't underline it and make it a hyperlink? I'm printing it on paper, so it doesn't need to be a hyperlink.

  • CSM TCL script or http checksum

    Hello, I need to do some HTTP keepalive based on the http page itself (no error code returned by the server). With the CSS we were able to do it because the css was doing a checksum of the http page. So when there was changes the service was consider

  • Problems with JSF and included subviews

    Hi everybody, I' ve got a problem with JSF and included subviews which makes me going crazy. I've got no clue why my web-pages are represent wrongly. The only tip I've got is that it must be connected with the kind I do include my JSF-pages. When I u