hi all

Can we (compile and execute) or just execute a c file from another c file?

am asked this question and i am unable to find any solution to this problem.

A 'c' file is executed and it must contain code that will execute another 'c' program
olease help me
thanks in advance

Recommended Answers

All 4 Replies

hi all

Can we (compile and execute) or just execute a c file from another c file?

am asked this question and i am unable to find any solution to this problem.

A 'c' file is executed and it must contain code that will execute another 'c' program
olease help me
thanks in advance

Is this possible?
help me please

Can we (compile and execute) or just execute a c file from another c file?

Yes. The easiest way would be to simply execute the compiler with the source file as input:

sprintf(cmd, "gcc %s", filepath);

system(cmd);       /* Compile */
system("./a.out"); /* Execute */

Otherwise you're looking at running the code through an interpreter of some sort, which could be as simple as using an existing interpreter similar to above, or writing a form of eval() that handles C code (not a task taken lightly).

Ultimately, I'd say that C probably isn't the correct choice of language if dynamic evaluation of code is a necessary feature.

does this works in turbo c?
am not sure that "gss" is used in turbo c
My sir said once about this as it will be in visual c++
well Narue what is 'cmd' in this code?

I tried it but its saying "undefined symbol".
can i know what the variable cmd' is for?

does this works in turbo c?

Change the name of the compiler to whatever you want.

am not sure that "gss" is used in turbo c

"gcc" refers to the GCC compiler.

My sir said once about this as it will be in visual c++

Visual C++'s compiler is called cl.exe.

well Narue what is 'cmd' in this code?

A string! Read up on sprintf(). The idea is that we need to build a command line statement that invokes a compiler with the specified file name.

I tried it but its saying "undefined symbol".

Duh. I posted a snippet, it's your job to fill in the blanks and make it compilable.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.