I want to access variable of c in system command but i do not know how to do it i tried like below but this does not works
#include<stdlib.h>
int main(){
int a=12;
system("echo $a");
}
You can't do this via any kind of string interpolation such as you've tried. What you need to do is build the command string before passing it to system()
.
#include <stdio.h>
#include <stdlib.h>
int main() {
int a = 12;
char command[100];
sprintf(command, "echo %d", a);
system(command);
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments