Link to home
Start Free TrialLog in
Avatar of cl071997
cl071997

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of imladris
imladris
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cl071997
cl071997

ASKER

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
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.
Thanks a lot.
Now the program works just fine.

Claes