regist.c

来自「linux下开发的一款类似于QQ的网络聊天室」· C语言 代码 · 共 53 行

C
53
字号
#include "main.h"#define P_MAX 1024int regist(char *name,char *passwd){	FILE *fp;	char *p;	char buff[P_MAX];	if((p=strchr(name,'\n'))!=NULL)		*p='\0';	if((p=strchr(passwd,'\n'))!=NULL)		*p='\0';	if((p=strchr(name,':'))!=NULL)	{		printf("username error!\n");		exit(1);	}	if((p=strchr(passwd,':'))!=NULL)	{		printf("password error!\n");		exit(1);	}	fp=fopen("passwd","r");	if(fp==NULL)	{		printf("open passwd error!\n");		exit(1);	}	while((fgets(buff,sizeof(buff),fp))!=NULL)	{		p=strchr(buff,':');		*p='\0';		if(strcmp(buff,name)==0)		{			return(-1);		}	}	fclose(fp);	fp=fopen("passwd","a");	if(fp==NULL)	{		printf("open passwd.txt error!\n");		exit(1);	}	strcpy(buff,name);	strcat(buff,":");	strcat(buff,passwd);	strcat(buff,"\n");	fputs(buff,fp);	fclose(fp);	return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?