IO进程线程 day1

Xmind
作业1:
 

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(int argc, const char *argv[])
{
	FILE *fp=fopen("./usr.txt","r");
	if(NULL==fp)
	{
		perror("fopen");
		return -1;
	}
	char a1[20]="";
	char a2[20]="";
	char a3[10][20];
	scanf("%s%s",a1,a2);
	int i=0;
	while(1)
	{
	if(fscanf(fp,"%s",a3[i])==EOF)
		break;
	i++;
	}
	for(int j=0;j<i;j++)
	{
		if(j%2==0)
		{
			if(strcmp(a1,a3[j])==0)
			{
				printf("用户存在\n");
				if(strcmp(a2,a3[j+1])==0)
				{
					printf("登录成功\n");
					goto LOOP;
				}
				else 
				{
					printf("密码错误\n");
					goto LOOP;
				}
			}
		}
	}
	printf("用户不存在\n");
LOOP:
	fclose(fp);
	return 0;
}

作业2:
 

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int file_size(char **s)
{
	FILE *fp=fopen(*s,"r");
	int i=0;
	int c;
	while(1)
	{
		c=fgetc(fp);
		if(c==EOF)
			break;
		i++;
	}
	fclose(fp);
	return i;
}
int file_line(char **s)
{
	FILE *fp=fopen(*s,"r");
	int i=0;
	int c;
	while(1)
	{
		c=fgetc(fp);
		if(c==10)
			i++;
		if(c==EOF)
			break;
	}
	fclose(fp);
	return i;
}
int main(int argc, const char *argv[])
{
	printf("------\n");
	char *s;
	scanf("%s",s);
	int a,b;
	a=file_size(&s);
	printf("文件大小为%d字节\n",a);
	b=file_line(&s);
	printf("文件的行号为%d\n",b);
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值