#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
struct fileinfo//文件大小,行数结构体
{
int lines;
int size;
};
struct fileinfo countline(const char* filename)
{
FILE* fp;
struct fileinfo info;
fp = fopen(filename, "r");
if ((int)fp == 0)
{
perror("openfile error:");
exit(0);
}
char buf[1024];
int lines = 0;
while (fgets(buf, 1024, fp))//若fgets返回NULL,则退出循环
{
lines++;
}
info.lines = lines;
info.size = ftell(fp);//此时fp指针指向文件末尾,ftell的返回值即为文件大小
fclose(fp);
return info;
}
#include<stdio.h>
#include<stdlib.h>
struct fileinfo//文件大小,行数结构体
{
int lines;
int size;
};
struct fileinfo countline(const char* filename)
{
FILE* fp;
struct fileinfo info;
fp = fopen(filename, "r");
if ((int)fp == 0)
{
perror("openfile error:");
exit(0);
}
char buf[1024];
int lines = 0;
while (fgets(buf, 1024, fp))//若fgets返回NULL,则退出循环
{
lines++;
}
info.lines = lines;
info.size = ftell(fp);//此时fp指针指向文件末尾,ftell的返回值即为文件大小
fclose(fp);
return info;
}