Your example code is OK and will execute the ping command. But if your parameters contain spaces, quotes or specific reserved characters, you must enclose these parameters by quotes. To be on the save side, you should also enclose the complete command by quotes. Your ping example would then look like this:
sprintf(buffer,"\"ping \"%s\"\"",p);
To make it more complicated, there is another special case when a parameter itself is enclosed by double quote characters. Then it must be enclosed by another pair of quotes.
The
system()
functions runs the command as 'cmd /c command'. You can open a command shell and execute 'help cmd' to get some information on quoting.