全球主机交流论坛
标题:
php按顺序逐行读取文本内容,怎么写
[打印本页]
作者:
muyang
时间:
2014-6-22 18:51
标题:
php按顺序逐行读取文本内容,怎么写
本帖最后由 muyang 于 2014-6-22 19:08 编辑
已解决。。
作者:
21andy
时间:
2014-6-22 20:06
fopen feof fread fgets
作者:
do99
时间:
2014-6-22 21:05
int
searchfile_dat(char *file, char *str)
{
FILE *fp;
char *line = NULL;
size_t len = 0;
ssize_t read;
int count = 0;
if ((fp = fopen(file, "r")) == NULL)
ERR_EXIT("fopen");
while ((read = getline(&line, &len, fp)) != -1)
{
if (memcmp(line, str, strlen(str)) == 0)
{
if (line)
free(line);
fclose(fp);
return count;
}
count++;
}
if (line)
free(line);
fclose(fp);
return -1;
}
欢迎光临 全球主机交流论坛 (https://hostloc.onozo.cc/)
Powered by Discuz! X3.4