IOday2作业

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, const char *argv[])
{
	FILE *fp_r=fopen(argv[1],"r");

	if(NULL==fp_r)
	{
		printf("line:%d\n",__LINE__);
		perror("fpoen");
		return -1;
	}
	
	char str[20];
	int count=0;
	while(NULL!=fgets(str,sizeof(str),fp_r))
	{
		if('\n'==str[strlen(str)-1])
			count++;
	}
	printf("size=%d\n",count);
	fclose(fp_r);

	return 0;
}

 

 

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include<unistd.h>
int main(int argc, const char *argv[])
{
	time_t t;
	struct tm* info;
	FILE *fp=fopen("./time.txt","a+");
	int count=1;
	char c;
	while(1)
	{
		count =1;
		rewind(fp);
		while(EOF!=(c=fgetc(fp)))
		{
			if('\n'==c)
				count++;
		}
		time(&t);
		info=localtime(&t);
		fprintf(fp,"[%d]%d-%02d-%02d %02d:%02d:%02d\n",count,\
				info->tm_year+1900,info->tm_mon+1,info->tm_mday,\
				info->tm_hour,info->tm_min,info->tm_sec);
		fflush(fp);
		sleep(1);
	}
	return 0;
}

实现注册功能,同一用户名不能重复注册

 

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, const char *argv[])
{
	FILE *fp=fopen("./url.txt","a+");
	char name[20]="",passwd[20]="";
	char name_r[20]="",passwd_r[20]="";
	printf("请输入要注册的用户名:");
	scanf("%s",name);
		while(-1!=fscanf(fp,"%s %s",name_r,passwd_r))
	{
		if(!strcmp(name,name_r))
		{
			printf("用户名已存在\n");
			return -1;
		}

	}
	printf("请输入要注册的密码:");
	scanf("%s",passwd);
	fprintf(fp,"%s %s\n",name,passwd);
	printf("注册成功\n");
	fclose(fp);
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值