Thread: Run command line code from within my c code.

  1. #1
    Registered User
    Join Date
    Jan 2010

    Run command line code from within my c code.

    Hi all,

    I'm very new to C programming, and currently working on an assignment for week 1 of class.

    Trying to get a little ahead by figuring out a way to execute a command line code from within the C program I'm writing.

    To be more precise, what I'm trying to do is to run a C program, type in some parameters, then compile a new file based on the parameters entered, and run the new file all in one go.

    I would greatly appreciate it if someone could show me how this can be done!

    I'm attaching the .c file...

  2. #2
    Fortran lover Epy's Avatar
    Join Date
    Sep 2009
    California, USA
    PROGRAM main
    PRINT *, "I love Fortran!"
    END PROGRAM main

  3. #3
    Registered User
    Join Date
    Jan 2010
    Thanks! system () is really useful...

    But I still can't get the second half of the code to compile a new file and run... any ideas??

  4. #4
    Registered User
    Join Date
    Jan 2010
    Easier than downloading:

    #include <stdio.h>

    float amp;
    int note;
    int main()

    // the part directly below is the "parameter input" part:
    printf("Amplitude?: ");
    scanf("%f", &amp);
    printf("\nMIDI Note?: ");
    scanf("%d", &note);

    // after a couple of things are typed in, I need <CsoundSynthesizer> and
    //</CsoundSynthesizer> and everything in between printed out and saved as
    // a .csd file... and if possible, run, all of this in one process.

    printf("sr = 44100\n");
    printf("ksmps = 4410\n");
    printf("kr = 10\n");
    printf("nchnls = 1\n");
    printf("instr 1\n");
    printf("a1 oscil %f, %d, 1\n", amp,note);
    printf("out a1\n");
    printf("f1 0 4096 10 1\n");
    printf("i1 0 3\n");

    return 0;

  5. #5
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    segmentation fault
    a .csd file
    You need to find out the way this file is formatted/structured (eg, plain text), then you can use fopen() and fwrite().
    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

  6. #6
    Registered User
    Join Date
    Jan 2010
    Trying to figure out fopen() and fwrite(), but not succeeding.

    Can someone show me exactly how this would be done?

    Not asking anyone to do my hw for me... this is actually a very, very simple rendition of what I'm working on for hw, and I'll be applying what I learn here to do much more.

    Please post if anyone can help!

  7. #7
    Registered User
    Join Date
    Jan 2010

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why my code works only in debug mode?
    By pingpangpang in forum C++ Programming
    Replies: 3
    Last Post: 06-04-2007, 12:39 PM
  2. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 10:20 AM
  3. How to run C code under VC environment?
    By robin in forum C Programming
    Replies: 12
    Last Post: 04-06-2005, 11:19 AM
  4. Determining required flops to run C code
    By mollyann in forum C Programming
    Replies: 5
    Last Post: 03-30-2005, 12:28 PM
  5. << !! Posting Code? Read this First !! >>
    By biosx in forum C++ Programming
    Replies: 1
    Last Post: 03-20-2002, 11:51 AM

Tags for this Thread