学习I/O的第一天

学习I/O的第一天_第1张图片

 

作业

#include 
#include 
#include 

int main(int argc, const char *argv[])
{
	char s[20]="";
	char q[20]="";
	printf("请输入账户密码:");
	scanf("%s %s",s,q);
	FILE* zh=fopen("usr.txt","r");
	if(NULL==zh)
	{
		perror("fopen");
		return -1;
	}
	char p[20]="";
	char p1[20]="";
	char a;
	fscanf(zh,"%s%c%s",p,&a,p1);
	printf("%s%c%s\n",p,a,p1);
	int zx=strcmp(s,p);
	int zx1=strcmp(q,p1);
	if(zx!=0)
	{
		printf("账户不存在\n");
	}
//	fscanf(zh,"%c",s);
//	fscanf(zh,"%s",p1);
	else if(zx1!=0)
	{
		printf("密码错误\n");
	}
	else
	{
		printf("登录成功\n");
	}
	return 0;
}

练习学习I/O的第一天_第2张图片

 

#include 
#include 
#include 

int main(int argc, const char *argv[])
{
	FILE* sp=fopen("1.txt","r");
	if(NULL==sp)
	{
		perror("fopen");
		return -1;
	}
	char c=0;
	FILE* rp=fopen("2.txt","w+");
	if(NULL==rp)
	{
		perror("fscanf");
		return -1;
	}
	while(fscanf(sp,"%c",&c)!=EOF)
	{
		fprintf(rp,"%c",c);
	}
	fclose(sp);
	fclose(rp);
	int count=0;
	int huanhuang=0;
	frp=fopen("2.txt","r");
	while(fscanf(rp,"%c",&c)!=EOF)
	{
		count++;
		if(c=='\n')
		{
			huanhuang++;
		}
		printf("%c",c);
	}
	printf("count=%d huanhuang=%d\n",count,huanhuang);
	fclose(rp);
	return 0;
}

你可能感兴趣的:(学习)