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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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\\batfi le ");
strcat(com,str1);
system(com);
printf(str1);
}
strcpy copies string 2 to string 1, strcat appends string 2 to string 1.
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\\batfi
strcat(com,str1);
system(com);
printf(str1);
}
strcpy copies string 2 to string 1, strcat appends string 2 to string 1.
ASKER
Thanks a lot.
Now the program works just fine.
Claes
Now the program works just fine.
Claes
ASKER
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