int main(void) {
char cmd_buf[100]
system("ping 192.168.1.1") /*仅为示范调用,具体情况具体对待*/
sprintf(cmd_buf, "ping %d.%d.%d.%d", 192, 168, 1, 1)
system(cmd_buf) /*ping 192.168.1.1*/
return 0
}
用system函数简单调用ping命令:#include "stdio.h"
void main()
{
char ip[15]
char command[50]
// printf("enter IP please: ")
scanf("%s",&ip[0])//输入要ping的ip
sprintf(command,"ping %s",ip)
system(command)
exit(0)
}
#include <string.h>#include <stdlib.h>
#include <stdio.h>
int main(void)
{
char abc[]="127.0.0."
char ip[15]
char cmd[20]="ping "
char d[]="1"
strcpy(ip,abc)
strcat(ip,d)
strcat(cmd,ip) <- 这时cmd中存放的是“ping 127.0.0.1”
printf("ping %8.11s",ip)
system(cmd)<- 相当于 system("ping 127.0.0.1")
return 0
} 望采纳
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)