0
votes

i was trying to make a program which calls an batch file by giving it a parameter. the main error is i am not able to pass/send the value/string of character to the batch file. when i run it displays the name of the char(or whatever it is called) but i want it to display the string stored in that char. the source code of the c program is:-

#include <stdio.h>
#include <stdlib.h>

void main(char a)
{
    a="hello sir";
    system("batch.bat a");
}

and the code for batch file is:-

@echo off
SET x=
SET x=%x%%1
ECHO %x%
PAUSE

save this file as batch.bat and run the c program. the output just displayed "a" not the value of a("hello sir") and i want it to display "hello sir" pleas try and answer as fast as possible.:-)

1
Nothing about that main is remotely standard compliant (well, besides the name).WhozCraig
Maybe something like system("batch.bat " + a); however I'm not sure about system() function in C/C++JosefZ
This was 3 years ago, i'm embarrassed that i asked such a trivial thing.Mukesh Tandale

1 Answers

0
votes

try something like that:

#include <stdio.h> 
#include <stdlib.h>

void main(char **arg)
{
  char cmd[20]="batch.bat ";
  strncat(cmd,argv[1],sizeof(cmd)-strlen(cmd)-1);
  system(cmd);
}