C语言:Math Dash练习的登录程序

注意:该程序会将账户数据存储到c盘里,名称是Number datas.db

代码如下:

#include 
#include 
#include 
#include 
typedef struct
{
	char *id,*password;
	int score;
}Elemtype;
struct LNode
{
	Elemtype data;
	struct LNode *next;
};
char *filename;
char *jia_string(char *a)
{
	int b;
	for(b=0;bdata=b;
	c->next=a;
	a=c;
	return a;
}
struct LNode *InItList()
{
	filename=(char*)malloc(sizeof(char));
	strcpy(filename,"C:\\Number datas.db");
	struct LNode *a;
	a=NULL;
	char *ok;
	ok=(char*)malloc(sizeof(char));
	if(_access(filename,F_OK)==-1)
	{
		strcpy(ok,"wt+");
	}
	else
	{
		strcpy(ok,"rt");
	}
	int a2=1;
	FILE*m=fopen(filename,ok);
	if(strcmp(ok,"rt")==0)
	{
		for(;;)
		{
			char *a1,*b,*c,*d,*g,*f;
			a1=(char*)malloc(sizeof(char));
			b=(char*)malloc(sizeof(char));
			c=(char*)malloc(sizeof(char));
			d=(char*)malloc(sizeof(char));
			g=(char*)malloc(sizeof(char));
			f=(char*)malloc(sizeof(char));
			fgets(a1,20,m);
			fgets(b,20,m);
			fgets(c,20,m);
			fgets(d,20,m);
			fgets(g,20,m);
			fgets(f,20,m);
			a1[strlen(a1)-1]=0;
			b[strlen(b)-1]=0;
			c[strlen(c)-1]=0;
			d[strlen(d)-1]=0;
			g[strlen(g)-1]=0;
			f[strlen(f)-1]=0;
			a1=jia_string(a1);
			b=jia_string(b);
			c=jia_string(c);
			d=jia_string(d);
			g=jia_string(g);
			f=jia_string(f);
			if((strcmp(a1,"id:")==0)&&(strcmp(c,"password:")==0)&&(strcmp(g,"score:")==0))
			{
				Elemtype e;
				e.id=b;
				e.password=d;
				e.score=atoi(f);
				a=cha_ru(a,e);
				free(a1);
				free(c);
				free(g);
				free(f);
			}
			else
			{
				free(a1);
				free(b);
				free(c);
				free(d);
				free(g);
				free(f);
				break;
			}
			a2++;
		}
	}
	fclose(m);
	free(ok);
	return a;
}
char *op(int a,char c[],int l)
{
	printf("请输入%s:",c);
	char *b;
	b=(char*)malloc(sizeof(char));
	int c0;
	for(;;)
	{
		gets(b);
		for(c0=0;c0a)
		{
			printf("%s过长!",c);
		}
		else if(strlen(b)data.id,b.id)==0)&&(strcmp(a->data.password,b.password)==0)))
		{
			break;
		}
		c=c->next;
	}
	return c;
}
char *jian_string(char *a)
{
	int b;
	for(b=0;bdata.id);
	    strcpy(g,b->data.password);
	    sprintf(h,"%d",b->data.score);
	    f=jian_string(f);
	    g=jian_string(g);
	    h=jian_string(h);
	    fprintf(fp,"%s\n%s\n%s\n%s\n%s\n%s\n",c,f,d,g,e,h);
	    free(f);
	    free(g);
	    free(h);
	    b=b->next;
	}
	free(c);
	free(d);
	free(e);
	fclose(fp);
}
struct LNode *chaxvn_charu(struct LNode *a,Elemtype b)
{
	struct LNode *c;
	c=a;
	while(c&&(strcmp(a->data.id,b.id)!=0))
	{
		c=c->next;
	}
	return c;
}
struct LNode *Delete(struct LNode *a,Elemtype b)
{
	struct LNode *c,*d;
	c=a;
	while((c)&&(!((strcmp(a->data.id,b.id)==0)&&(strcmp(a->data.password,b.password)==0))))
	{
		d=c;
		c=c->next;
	}
	if(c!=a)
	{
		free(c->data.id);
	    free(c->data.password);
	    d->next=c->next;
	    free(c);
	}
	else
	{
		struct LNode *a1;
		a1=a;
		a=a->next;
		free(a);
	}
	return a;
}
struct LNode *da_f1(struct LNode *a,struct LNode *g)
{
	printf("请输入您要的算式数量(每答对一道送20分)\n");
    char *a1;
    a1=(char*)malloc(sizeof(char));
    int b1;
    do
    {
    	gets(a1);
    	for(b1=0;b1'9'))
    		{
    			break;
    		}
    	}
    }while((b1==0)||(b1!=strlen(a1)));
    int u1,c1;
    for(u1=0;u1100)
		{
			c1=1+rand()%(100-b1);
		}
    	if(math(c1,b1)==c1+b1)
    	{
    		g->data.score=g->data.score+20;
    		FputsList(a);
    		printf("回答正确!\n");
    	}
    	else
    	{
    		printf("回答错误!\n");
    	}
    }
    free(a1);
    return a;
}
double math_gets_double()
{
	char *c;
	c=(char*)malloc(sizeof(char));
	int d;
	do
	{
		gets(c);
		for(d=0;ddata.score=a0->data.score+150;
		FputsList(b0);
		printf("回答正确!\n");
	}
	else
	{
		printf("回答错误!\n");
	}
	return b0;
}
struct LNode *games(struct LNode *a,Elemtype b)
{
	char *c;
	c=(char*)malloc(sizeof(char));
	do
	{
		puts("1.【注         销】\n2.【10 0以内加 法】\n3.【退         出】\n4.【查         分】\n5.【修 改 用户 名】\n6.【修  改 密  码】\n7.【计 算 平均 数】");
    	for(;;)
    	{
    		gets(c);
    		if((strcmp(c,"1")==0)||(strcmp(c,"2")==0)||(strcmp(c,"3")==0)||(strcmp(c,"4")==0)||(strcmp(c,"5")==0)||(strcmp(c,"6")==0)||(strcmp(c,"7")==0))
    		{
    			break;
    		}
    		else if(strlen(c)==0)
    		{
    			printf("内容不能为空!");
    		}
    		else
    		{
    			printf("您输入的指令有误!");
    		}
    		printf("请重新输入,重新输入的内容为:");
    	}
    	if(strcmp(c,"3")!=0)
    	{
    		struct LNode *g;
    		g=a;
    		while(g&&(!((strcmp(g->data.id,b.id)==0)&&(strcmp(g->data.password,b.password)==0))))
    		{
    		    g=g->next;
    		}
    		if(strcmp(c,"1")==0)
    	    {
    		    a=Delete(a,b);
    		    FputsList(a);
    		    printf("注销成功!\n");
    	    }
    	    else if(strcmp(c,"4")==0)
    	    {
    	    	printf("游戏分数:%d\n",g->data.score);
    		}
    		else if((strcmp(c,"5")==0)||(strcmp(c,"6")==0))
    		{
    			if(strcmp(c,"5")==0)
    		    {
    			    free(b.id);
    			    b.id=op(20,"用户名",0);
    			    free(g->data.id);
    			    g->data.id=b.id;
			    }
			    else
			    {
				    free(b.password);
				    b.password=op(15,"密码",6);
				    free(g->data.password);
				    g->data.password=b.password;
			    }
			    FputsList(a); 
			}
			else if(strcmp(c,"7")==0)
			{
				a=da_f2(g,a);
			}
    	    else
    	    {
    		    a=da_f1(a,g);
    	    }
    	}
    	if((strcmp(c,"3")!=0)&&(strcmp(c,"1")!=0))
    	{
		    system("pause");
		}
    }while((strcmp(c,"3")!=0)&&(strcmp(c,"1")!=0));
	free(c);
	if(!((strcmp(c,"5")==0)||(strcmp(c,"6")==0)))
	{
		free(b.id);
	    free(b.password);
	}
	return a;
}
int math_gets()
{
	char *c;
	c=(char*)malloc(sizeof(char));
	int d;
	do
	{
		gets(c);
		for(d=0;d

程序运行如下:

C语言:Math Dash练习的登录程序_第1张图片

你可能感兴趣的:(编程,科学技术,计算机科学,c语言,开发语言)