当前位置: 技术问答>linux和unix
这个执行命令代码,好多看不懂,求解释下
来源: 互联网 发布时间:2017-04-26
本文导语: #include #include #include #include #include #define oops(m) do{perror(m); exit(1);}while(0) int main() { char buf[32]; int pid = 0; int num = 0; int i = 0; int flag = 0; char * p = NULL; while (1) { flag = 0; i = 0; num = 0; p...
#include
#include
#include
#include
#include
#define oops(m) do{perror(m); exit(1);}while(0)
int main()
{
char buf[32];
int pid = 0;
int num = 0;
int i = 0;
int flag = 0;
char * p = NULL;
while (1)
{
flag = 0;
i = 0;
num = 0;
printf("Please input a cmd: ");
fgets(buf, 32, stdin);
if (strncmp(buf, "end", 3) == 0)
break;
p = strstr(buf, "n");
if (p != NULL)
*p = '';
while (buf[i] != '')
{
if (buf[i] == ' ' && buf[i+1] != ' ')
{
num++;//这里不懂
flag = 1;//还有这里,所谓的标记,是什么意思
}
else
flag = 0;//???
i++;
}
char* argv[num+2];// 为什么又是+2
argv[num+1] = NULL;
p = buf;
for (i = 0; i
#include
#include
#include
#include
#define oops(m) do{perror(m); exit(1);}while(0)
int main()
{
char buf[32];
int pid = 0;
int num = 0;
int i = 0;
int flag = 0;
char * p = NULL;
while (1)
{
flag = 0;
i = 0;
num = 0;
printf("Please input a cmd: ");
fgets(buf, 32, stdin);
if (strncmp(buf, "end", 3) == 0)
break;
p = strstr(buf, "n");
if (p != NULL)
*p = '';
while (buf[i] != '')
{
if (buf[i] == ' ' && buf[i+1] != ' ')
{
num++;//这里不懂
flag = 1;//还有这里,所谓的标记,是什么意思
}
else
flag = 0;//???
i++;
}
char* argv[num+2];// 为什么又是+2
argv[num+1] = NULL;
p = buf;
for (i = 0; i