Using Variables with th 'System' command [Archive] - C Board

PDA

View Full Version : Using Variables with th 'System' command


dapernia
09-15-2003, 02:25 PM
Hi friends:

I have a tiny problem.
I want to graph some data i have stored in a file with the RRDtool program. This RRDTooll program works with shell commands:
rrdtool create test.rrd \
--start 920804400 \
DS:speed:COUNTER:600:U:U RRA \

etc, etc

Now, I want to make a C program to graph these data. But i don't know how to add variables with the system command
system("rrdtool create test.rrd --start %s ...",a);

How can i do that in C. or How could i do that in a shell script????

Please Help me!

Hammer
09-15-2003, 03:52 PM
Use a buffer to hold the string, something like:
char buf[1024];
Put you commands in there (maybe using strcpy(), sprintf() etc), then call system(buf);

Alternatively, read the FAQ (http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1044654269&id=1043284392)

dapernia
09-15-2003, 05:11 PM
Thanks a lot
:D