#define LONLAT "./LonLat_20190128.txt"
int GetTxtLine(const char *filename)
{
FILE *fd;
int count = 0;
if (fd = fopen(filename,"r"))
{
while (!feof(fd))
{
if ('\n' == fgetc(fd))
{
count ++;
}
}
}
printf("count: %d\n", count);
if (fd)
{
fclose(fd);
}
return count;
}
使用举例:
int linecount = 0;
linecount = GetTxtLine(LONLAT );
linecount的值就是LONLAT 文本里的内容总的行数。
网友评论