gpt4 book ai didi

c - 使用 control+D (EOF) 但返回意外字符 D

转载 作者:太空宇宙 更新时间:2023-11-04 06:14:37 25 4
gpt4 key购买 nike

<分区>

我正在编写一个非常简单的程序,通过输入 stdin 并返回找到该模式的时间来检测单词模式。然而,代码返回了正确的数字,但后面是一个字符 D。

#include <stdio.h>
#include "string.h"

#define MAXLINE 1000 /* maximum input line length */

char pattern[] = "ould"; /* pattern to search for */

/* print all lines from standard input that match pattern */
int main()
{
char line[MAXLINE];
int found = 0;

while (fgets(line, MAXLINE, stdin) != NULL)
if (strstr(line, pattern) != NULL) {
printf("%s", line);
found++;
}
printf("%d \n", found);
return 0;
}

结果:

glaroam2-180-76:Lab2 apple$ ./find0
fould
fould
1D

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com