Welcome, Guest. Please login or register.

Author Topic: Simple C programming question.  (Read 1978 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline elendilTopic starter

  • Sr. Member
  • ****
  • Join Date: Nov 2002
  • Posts: 324
    • Show only replies by elendil
    • http://www.idiot.fnuck.dk
Simple C programming question.
« on: February 25, 2003, 11:50:26 AM »
Mjallow.

I was just wondering if it is possible to easily execute programs within a C program.

What I mean is that I remember arexx had a command (forgot the name) that would do:
command-name c:wait 10, for example, running the wait program.

I could use that functionality, at least, though you probably shake your heads at me :)

Sincerely,

-Kenneth Straarup.
 

Offline elendilTopic starter

  • Sr. Member
  • ****
  • Join Date: Nov 2002
  • Posts: 324
    • Show only replies by elendil
    • http://www.idiot.fnuck.dk
Re: Simple C programming question.
« Reply #1 on: February 25, 2003, 11:58:16 AM »
Also what am I to do with the a.out file gcc produces when I type gcc filename? I am lousy at this, I know, I am used to java and lpc without linkers and makefiles and what-not I have on clue about :)

Sincerely,

-Kenneth Straarup.

EDIT: I just noticed I posted this in software discussion or something. I am not fully into this, I just his post new thread while reading another. Sorry for any inconvenience.
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: Simple C programming question.
« Reply #2 on: February 25, 2003, 12:04:41 PM »
There is an ANSI C function called system() in the stdlib.h header (I think). It runs a synchronous (AFAIR) command at the console, eg

#include
#include

int main()
{
    puts("Launching multiview!");
    system("SYS:Utilities/Multiview WINDOW");
    return 0;
}

If sucessful, the above C program should run multiview with a blank window.

I use something like this for opening debug files I generate inside my own code, so can assure you it works ;-)

-edit-

AFAIK, a.out is just the default executble name for the generated program. Check the docs for info on how to set the executable name that gcc produces. In any event, try running it at the shell and see what happens. Hopefully it's just your program...
Sorry if this seems a bit scant, I had scripts set up for all this stuff yonks ago and forgor simple things like that ;-)
int p; // A
 

Offline elendilTopic starter

  • Sr. Member
  • ****
  • Join Date: Nov 2002
  • Posts: 324
    • Show only replies by elendil
    • http://www.idiot.fnuck.dk
Re: Simple C programming question.
« Reply #3 on: February 25, 2003, 12:14:40 PM »
Hey!

You were right. a.out was my compiled program. I just thought I remembered that stormC generated an a.out file AND a file to be executed, but I am probably wrong (it was a long time ago).

I will go try that System-thing right away. Thank you for your help.

Sincerely,

-Kenneth Straarup.
 

Offline elendilTopic starter

  • Sr. Member
  • ****
  • Join Date: Nov 2002
  • Posts: 324
    • Show only replies by elendil
    • http://www.idiot.fnuck.dk
Re: Simple C programming question.
« Reply #4 on: February 25, 2003, 12:25:15 PM »
And as you promised the system() function worked super as well.

Even though I forgot the include, but I suppose gcc included it for me then.

Sincerely,

-Kenneth Straarup.
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16879
  • Country: gb
  • Thanked: 5 times
    • Show only replies by Karlos
Re: Simple C programming question.
« Reply #5 on: February 25, 2003, 12:30:54 PM »
Jolly good ;-)

A quick point -  always include the appropriate headers. If you don't, when the compiler sees you use a new function for the first time, it assumes that usage is the correct prototype for the function and will complain if you use it differently later. Big problem for variable argument length functions like printf().
int p; // A
 

Offline elendilTopic starter

  • Sr. Member
  • ****
  • Join Date: Nov 2002
  • Posts: 324
    • Show only replies by elendil
    • http://www.idiot.fnuck.dk
Re: Simple C programming question.
« Reply #6 on: February 26, 2003, 08:16:20 AM »
Roger that and thanks again.

Sincerely,

-Kenneth Straarup