#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, const char *argv[])
{
//以读的方式打开源文件
FILE *fp=fopen("usr.txt","a+");
if(NULL == fp)
{
printf("__%d__\n",__LINE__);
perror("fopen");
return -1;
}
printf("fopen success");
char a[20]="";
char b[20]="";
printf("请输入账号:");
scanf("%s",a);
printf("请输入密码:");
scanf("%s",b);
char c[20]="";
char d[20]="";
int e=0;
while(1)
{
e=fscanf(fp,"%s%s",c,d);
if(EOF == e)
{
break;
}
if(0==strcmp(a,c)&&0==strcmp(b,d))
{
printf("登录成功\n");
break;
}
else if(0!=strcmp(a,c)&&0==strcmp(b,d))
{
printf("用户不存在\n");
break;
}
else
{
printf("密码错误\n");
break;
}
}
if(fclose(fp)<0)
{
perror("fclose");
return -1;
}
printf("fclose success");
return 0;
}
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(int argc, const char *argv[])
{
intcount1 = 0,count2 = 0;
char c = 0;
int res = 0;
FILE *fp = fopen("2.txt","r");
FILE *fp2 = fopen("1.txt","w+");
while(EOF != (c = fgetc(fp)))
{
fputc(c,fp2);
count1++;
if('\n' == c)
{
count2++;
}
}
fclose(fp2);
fp2 = fopen("1.txt","r");
while(EOF != (c = fgetc(fp2)))
{
printf("%c",c);
}
fclose(fp);
fclose(fp2);
printf("2.txt共有%d个字节,共有%d行\n",counter1,count2);
return 0;
}