我正在寻找一种方法来确定某个文件是否包含某个字符串。可以是系统调用,也可以是 C 函数,没关系。
我用 grep 试过了,但它没有返回任何东西
//name is the directory entry name
char grepcmd[150];
strcpy(grepcmd,"grep -c hello ");
strcat(grepcmd, name);
int status = system(grepcmd);
最佳答案
你做得很好。 status
如果您给定的名为 name
的文件包含 hello
字符串,则 status
应该为零。否则它应该是非零值。
关于c - 判断一个文件是否包含某个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13736541/