我正在嘗試在C中編寫一個程序來搜索某個文件中的單詞 請問您可以幫我嗎?如何在函數中使用grep?
#include<unistd.h>
#include<sys/types.h>
#include<stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>
int main()
{
int pid;
//string s;
//s = grep();
pid = fork();
if(pid < 0)
{
printf("Failed");
exit(-1);
}
else if (pid == 0)
{
printf("Child id %d\n",getpid());
execlp("/bin/bzexe","grep the", NULL);
}
else
{
wait(NULL);
printf("Parent id %d |\n ",getpid());
exit(0);
}
return 0;
}
什麼是'bzexe'? – Barmar
這是一個文件... – Emad