C语言无法让strcmp工作

标签 c strcmp

我已经编写了下面的代码,但是 strcmp 函数无法正常工作。它不会从文本文件中提取已知文本并返回 0 字数。

int count = 0;
char line[400];
char word[20];

printf("Search for? \n");
scanf_s("%s", word, 19);

if (Fp == NULL)
{
    printf("File not found");
}
while (!feof(Fp))
{
    fgets(line, 150, Fp);

    if (strcmp(line, word) == 0) //searches the line to find word
    {
        count++;//increment
    }
}

printf("Search returned %s was found %d number of times", word, count);

最佳答案

不要使用 strcmp(),试试这个:

if (strstr(line, word)) { ... } 

关于C语言无法让strcmp工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40918807/

相关文章:

c - 如何检查 C 中的 "backspace"字符

c - C 中的变量类型说明符

mysql - 为什么这个 strcmp() 语法在 mysql-5.7 中给我一个错误?

检查字符串是否为空,然后继续

c - 内存映射 POSIX 中的文件

通过地址 C 调用函数

C : Comparing 2 Strings

c - 可加载的 Bash 内置

c++ - 是否内联这个函数?

c - IP_RECVDSTADDR 未定义