网站首页 > 文章中心 > 其它

c语言注册登录函数

作者:小编 更新时间:2023-09-25 14:45:32 浏览量:70人看过

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

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

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

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

要调用Windows

API的RegOpenKeyEx(),

RegSetValueEx(),

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

c语言注册登录函数-图1

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";

vname[]

"RunMyProg";

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,

exefile,

strlen(exefile)+1);

//就加上.

}

RegCloseKey(hKey);

//关闭.

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

#include stdio.h

#include string.h

int main()

char acct_no[11];

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

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;

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))

else

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

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

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

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

void regis() {

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

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

while (true) {

printf("Press the password again: ");

scanf("%s", tpass);

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

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

break;

_add(id, pass);

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

void init() {

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

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

system("pause");

exit(0);

int main(void){

int command;

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

scanf("%d", command);

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

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

else if (command == 1) {

if (!login())

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

printf("Login successfully!\n");

regis();

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

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

首先看下fwrite的原型

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

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

scanf("%s",c1);

scanf("%s",d1);

iu++;

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

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

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

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

以上就是土嘎嘎小编为大家整理的c语言注册登录函数相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!

版权声明:倡导尊重与保护知识产权。未经许可,任何人不得复制、转载、或以其他方式使用本站《原创》内容,违者将追究其法律责任。本站文章内容,部分图片来源于网络,如有侵权,请联系我们修改或者删除处理。

编辑推荐

热门文章