• C

Invoke a dos bat-file into the program

Hi

Let´s say that I need to put in an ordinary dos-batch file into this program:

#include "stdio.h"

main()
{
char str1[80];

printf("enter a text\n:");
gets(str1);

# here come the dos bat-file
>c:\dos\batfile.bat <argument>

printf(str1);
}

How do I solve this.
Im a newbe in c-programming.

Regards
Claes
Sweden

cl071997Asked:
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.

imladrisCommented:
You can invoke anything that you can invoke from the commandline with the system function.

In this case you would write:

   system("c:\\dos\\batfile.bat arg");
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
cl071997Author Commented:
Thanks.
So easy...
I forgot to tell you that the argument in the bat-file should be "str" - the argument we got earlier in the program...sorry
Is it possible to put that variable in...?

Regards
Claes
0
imladrisCommented:
I assume you mean str1 from the example in the question?

In that case the code would be:

#include "stdio.h"

main()
{
char str1[80],com[200];

printf("enter a text\n:");
gets(str1);

strcpy(com,"c:\\dos\\batfile ");
strcat(com,str1);
system(com);

printf(str1);
}

strcpy copies string 2 to string 1, strcat appends string 2 to string 1.
0
cl071997Author Commented:
Thanks a lot.
Now the program works just fine.

Claes
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
C

From novice to tech pro — start learning today.