chouaib23 chouaib23 - 1 year ago 57
C Question

Too many arguments in system() call

I have a problem with arguments in the

call in C.


char macaddr[13];
uint8_t mac[6];
memset(macaddr, '\0', 13);
mac_get_ascii_from_file("/sys/class/net/eth0/address", macaddr);

system("rm /var/tuxbox/config/cxx.bin");
system("wget -P /var/tuxbox/config http://xxxxxxx/xx/cxx_%s.bin\n", macaddr);

Error message:

too many arguments to function 'system'

Answer Source

system() doesn't handle printf style arguments. You need to build the command string up first and then pass it to system.


char cmd[512];
sprintf(cmd, "wget -P /var/tuxbox/config http://xxxxxxx/xx/cxx_%s.bin\n", macaddr);
// or snprintf(cmd, sizeof(cmd), "wget...

(note, no error handling etc included.)