成都创新互联网站制作重庆分公司

c语言注册登录函数,c语言函数

如何用C语言编程实现用户登录

C语言的话,一般用户信息存储在结构体链表里

成都创新互联是一家集网站建设,江安企业网站建设,江安品牌网站建设,网站定制,江安网站建设报价,网络营销,网络优化,江安网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。

你输入用户名回车以后,需要遍历链表,使用strcmp()函数逐一对比链表里是否存储了你输入的用户名。不存在输出“无此用户”,存在继续输入密码,将密码与此结点的密码信息对比,处理方式同用户名;

至少三次输入错误,可设一个整形变量index = 0,每错误一次执行index++,当if(index==3)成立时,输出相应信息,并执行exit(1);

C语言中的注册表操作函数有哪些?

要调用Windows

API的RegOpenKeyEx(),

RegSetValueEx(),

RegSetValueEx()等函数。首先要确认你的C编译器支持调用Windows

API.

举例:

要自动运行"D:\Myprog\MyProgram.exe",

修改注册表,在

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run

中加一项:

RunMyProg="D:\Myprog\MyProgram.exe"

#include

windows.h

static

char

subkey[]

=

"Software\\Microsoft\\Windows\\CurrentVersion\\Run";

static

char

vname[]

=

"RunMyProg";

static

char

exefile[]

=

"D:\\Myprog\\MyProgram.exe";

ULONG

dType

=

REG_SZ,

len

=

0;

HKEY

hKey;

RegOpenKeyEx(HKEY_LOCAL_MACHINE,subkey,0,KEY_SET_VALUE|KEY_QUERY_VALUE,hKey);//打开。

if

(RegQueryValueEx(hKey,

vname,

0,

dType,

NULL,

len))

{

//如果没有RunMyProg,

RegSetValueEx(hKey,

vname,

0,

REG_SZ,

exefile,

strlen(exefile)+1);

//就加上。

}

RegCloseKey(hKey);

//关闭。

C语言 编写一个注册函数 要求账号10位字符 密码6位字符 账号密码同时满足条件显示注册成功

#include stdio.h

#include string.h

const char *const ACCT[]="1234567890"

const char *const PSWD[]="123456";

int main()

{

char acct_no[11];

char passwd[7];

gets(acct_no);

gets(passwd);

if ( strcmp(acct_no,ACCT) || strcmp(passwd,PSWD) )

{

printf("账户或密码错误!\n");

return -1;

}

printf("注册成功!\n");

return 0;

}

编一个注册登陆的程序 C语言的

#include stdlib.h

#include stdio.h

#include string.h

bool search(char id[], char pass[]) {

FILE *fp;

char tid[10], tpass[10];

fp = fopen("c:\\data", "r");

while (!feof(fp)) {

fscanf(fp, "%s%s", tid, tpass);

if (strcmp(tid, id)==0 strcmp(tpass, pass)==0) {

fclose(fp);

return true;

}

}

fclose(fp);

return false;

}

bool login() {

char id[10], pass[10];

printf("Login\nPress the id: ");

scanf("%s", id);

printf("Press the password: ");

// 可以自行将password处理成*号, 如果不会可以发信给我

scanf("%s", pass);

printf("-----------------------");

if (search(id, pass))

return true;

else

return false;

}

void _add(char id[], char pass[]) {

FILE *fp;

fp=fopen("c:\\data", "a");

// 在写入文件时可以按一定的排序方式插入,可减少以后Login时的search时间

fprintf(fp, "%s %s\n", id, pass);

fclose(fp);

}

void regis() {

char id[10], pass[10], tpass[10];

printf("Register\nPress the id: ");

scanf("%s", id);

while (true) {

printf("Press the password: ");

scanf("%s", pass);

printf("Press the password again: ");

scanf("%s", tpass);

if (strcmp(pass, tpass) != 0)

printf("The passwords you pressed are not the same!\n");

else

break;

}

_add(id, pass);

printf("-----------------------Register successfully!\n");

}

void init() {

FILE *fp;

if ((fp=fopen("c:\\data", "r")) == NULL) { // 注意,一定要有个名叫data(没有扩展名)的合法文件在C盘根目录

printf("---------File is not exist\n");

system("pause");

exit(0);

}

else

fclose(fp);

}

int main(void){

int command;

init(); // 检查data文件在不在

while (true) {

printf("-----------------------(Login: 1 Register: 2 Exit: 3)\n");

scanf("%d", command);

printf("-----------------------\n");

// 这里可以编写command的检测语句

if (command == 3)

break;

else if (command == 1) {

if (!login())

printf("ID is not exist or password is wrong!\n");

else

printf("Login successfully!\n");

}

else

regis();

}

return 0;

}

搞定了。。。我是用成功了的。。。如果有问题就发信给我。。。。

大家帮忙看一下我的C语言注册登录函数写的哪里不对?

首先看下fwrite的原型

size_t fwrite(const void* buffer,size_t size,size_t count,FILE* stream);

(1)buffer:是一个指针,对fwrite来说,是要输出数据的地址。

(2)size:要写入内容的单字节数;

(3)count:要进行写入size字节的数据项的个数;

(4)stream:目标文件指针。

printf("请输入用户名(最大7位):");

scanf("%s",c1);

fwrite(c1,8,1,fp); // line one

printf("请输入密码(最大15位):");

scanf("%s",d1);

fwrite(d1,16,1,fpm); //line two

line one 的参数应该是(c1,sizeof(char),8,fp);

line two 的参数应该是(d1,sizeof(char),16,fpm);

while(s2[iu]!='\0')

{

fread(s2[iu],sizeof(char),1,fp);

iu++;

fp++; //这里是不需要的,文件读取之后文件内部指针会自动移动

} //还有这里是可以一次读取出来的,为什么不这样做呢?

下面读取密码的时候也是一样,其他暂时没看出什么来。。。。

读取出的东西不对,除了读取的方式有错,再就是本来写入的数据就是错误的、


网页标题:c语言注册登录函数,c语言函数
分享URL:http://cxhlcq.com/article/hscpss.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部