automaticly run the C source code

ok, i have a few C source code in particular folder
i need to build a application that will automaticly run the source code
And the application will be linking to a C compiler (let say Turbo C)
In the checking process, i need to input value to test the output. the input value will be keep in the database.
The problem is how do i interact with the Turbo C. I been able to callout the program but how do i input the value from database that i extract out
And finally get the output

THANX  
winsonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chnelsonCommented:
what u mean to link to a C compiler...
r u going to implement to by using a vb function named Shell?

If it is true, now you have a problem on how to put the test value from a database to perform some kind of 'stress test'?

m i understand your problem precisely?

i need further info.
would u mind to tell me the details of your test program?

i dont understand one thing:
what u mean automcatically run the source code...
- u mean compile your source code?
or
- execute your test program?
0
winsonAuthor Commented:
ok
let's make this simple
if i have a C source code, normally i have to open Turbo C(or Borland C) to compile and run the program.
in order to test the program whether if it is correct, i must manually click the run button and key in the input value to test if the source code output the right value
but i want to automate this step with a application only

hope this clear
THANX A LOT
0
chnelsonCommented:
ar ha. i get a more clear image now

try to define some arguments in your main()
so that you can execute your C program like this:

mobilephone.exe ericsson, motorola, nokia

like this: (i quoted the following codes from MSDN)

#include <iostream.h>
#include <string.h>

void main( int argc, char *argv[], char *envp[] )
{
    int iNumberLines = 0;    // Default is no line numbers.

    // If more than .EXE filename supplied, and if the
    // /n command-line option is specified, the listing
    // of environment variables is line-numbered.

    if( argc == 2 && stricmp( argv[1], "/n" ) == 0 )
        iNumberLines = 1;

    // Walk through list of strings until a NULL is encountered.
    for( int i = 0; envp[i] != NULL; ++i )
    {
        if( iNumberLines )
            cout << i << ": " << envp[i] << "\n";
    }
}



Now, the 2nd thing you have to do is about extract those test values (i.e. the brand name of mobile phone in the above example) from a database using VB.

You can easily implement it by usng VB ADO control and a text file or access mdb as the database.

One more thing you may wanna also to do:
invoke the C program compilation resides VB
it is not difficult, as you know how to use "Shell" in VB

Try to find how to use command-line to compile your C program in turbo C. then you will know how to do it

i think it should be something like this:
tc.exe mobliephone.c -o mobilephone.exe


Hope i can help you.
Enjjoy!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

chnelsonCommented:
one thing i have to remind you that,
now you can use scanf to get data input
you should use the arguments in your main instead

so that no interaction within your program.

since after vb execute your program the DOS screen will be disappeared,
so that i think u better write the output into a text file instead of using printf to display the result.
0
winsonAuthor Commented:
sorry for the delay if reply
the last request is how do i use the shell in VB programming
can u please give me a clearer picture
i haven't use the shell in VB before

THANX AGAIN
0
winsonAuthor Commented:
sorry for the delay if reply
the last request is how do i use the shell in VB programming
can u please give me a clearer picture
i haven't use the shell in VB before

THANX AGAIN
0
chnelsonCommented:
Here i quoted a sample code from MSDN.

' Specifying 1 as the second argument opens the application in
' normal size and gives it the focus.
Dim RetVal
RetVal = Shell("C:\WINDOWS\CALC.EXE", 1)   ' Run Calculator.

So you may change the above to:
RetVal = Shell("C:\TC\BIN\TC.EXE mobilephone.c -o mobilephone.exe", 6)

6 stands for Window is displayed as an icon. The currently active window remains active.

If you need further help, i can email you a html which show details on VB Shell function.
or you can go to msdn.microsoft.com and then search Shell function.
0
winsonAuthor Commented:
yes
please mail me the details
but you have to give me time to digest this things before the point is given

THANX ANYWAY
0
winsonAuthor Commented:
my email
pohkheng@tm.net.my
0
winsonAuthor Commented:
one last question

u said
"so that i think u better write the output into a text file instead of using printf to display the result. "

can i do it the printf way and how am i going to get the output value
0
chnelsonCommented:
The method of how to interact your VB program and your C program is that:

try to get rid of asking user to input (your test values) for example scanf

so you may ask, how do i input those test values?!?!

i recommend you try to define parameters in your main()
so that you can execute your C program like this:

myCProg.exe "data1", "data2", "data3"

the no. of parameters depends on the no. of your test data input (no. of scanf) in your C program.

so that you can combine to above technique with using VB Shell command.
0
winsonAuthor Commented:
ok
if i now change the Turbo C to Borland C++
can i do the same thing
0
chnelsonCommented:
yup!
as you know how to invoke the compiler in Borland C++

i think the filename may be bcc.exe or bc.exe something like that
the most important is that it supports command-line operation

so that no IDE is loaded while performing the compilation.

Good Luck!
0
winsonAuthor Commented:
About the code below
how do i get the input
ok, let say that i want to input 2 value and add it up
the result be write to a file
can you please show me the coding for this
THANX A LOT

#include <iostream.h>
#include <string.h>

void main( int argc, char *argv[], char *envp[] )
{
    int iNumberLines = 0;    // Default is no line numbers.

    // If more than .EXE filename supplied, and if the
    // /n command-line option is specified, the listing
    // of environment variables is line-numbered.

    if( argc == 2 && stricmp( argv[1], "/n" ) == 0 )
        iNumberLines = 1;

    // Walk through list of strings until a NULL is encountered.
    for( int i = 0; envp[i] != NULL; ++i )
    {
        if( iNumberLines )
            cout << i << ": " << envp[i] << "\n";
    }
}
0
winsonAuthor Commented:
sorry
it is not
"how do i get the input"
but "how i put the input"
0
chnelsonCommented:
So, in your VB calling program,
call this program like this:
shell "calc " & num1[i] & " " & num2[i]

which inside a for loop (for your no. of pairs of the test data)

tell me if you still have problems.

#include <iostream.h>
#include <string.h>
#include <stdlib.h>
void main( int argc, char *argv[], char *envp[] ) {

      float lfNum1, lfNum2;

      lfNum1 = atof(argv[1]);
      lfNum2 = atof(argv[2]);
      
      cout << lfNum1 + lfNum2 << "\n";
}
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.