#include<myhead.h>
int size(FILE *fp)
{
if (NULL == fp)
{
perror("fopen error");
return -1;
}
char c;
int count = 0;
while (1)
{
c = fgetc(fp);
if (EOF == c)
break;
count++;
}
return count;
}
int num(FILE *fp)
{
if (NULL == fp)
{
perror("fopen error");
return -1;
}
char c;
int count = 1;
while(1)
{
c = fgetc(fp);
if (EOF == c)
break;
if(c == '\n')
count++;
}
return count;
}
int main(int argc, const char *argv[])
{
FILE *fp = fopen(argv[1], "r");
if (NULL == fp)
{
perror("fopen error");
return -1;
}
int count1 = size(fp);
fclose(fp);
FILE *fp2 = fopen(argv[1], "r");
int count2 = num(fp2);
printf("该文件大小为%d, 有%d行\n", count1, count2);
fclose(fp2);
return 0;
}
#include<myhead.h>
int local(FILE*fp)
{
if(NULL==fp){
perror("fopen");
return -1;
}
char str1[10];
char str2[10];
printf("请输入账号:");
scanf("%s",str1);
printf("请输入密码:");
scanf("%s",str2);
char a[10];
while(1){
fscanf(fp,"%s",a);
if(strcmp(str1,a)==0){
fscanf(fp,"%s",a);
if(strcmp(str2,a)==0){
printf("账号登录成功\n");
return 0;
}else if(strcmp(str2,a)!=0){
printf("密码输入错误\n");
return 0;
}
}
if(fscanf(fp,"%s",a)==EOF){
printf("账号不存在\n");
break;
}
}
return 0;
}
int main(int argc, const char *argv[])
{
FILE*fp =fopen("./usr.txt","r");
local(fp);
fclose(fp);
return 0;
}