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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
imladrisConnect With a Mentor Commented:
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
 
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
All Courses

From novice to tech pro — start learning today.