C語言利用鍊錶與檔案實現登入註冊功能

2022-09-26 10:57:20 字數 1603 閱讀 3812

c語言實現簡登入和註冊功能,供大家參考,具體內容如下

c語言實現註冊登入

使用鍊錶

使用檔案

版本二: 利用鍊錶

此版本使用的鍊錶,第乙個版本使用的是陣列

陣列版本連線

這裡我使用的線性鍊錶,一定要注意在判斷語句或賦值語句中不可將指標指向未定義的區域,這會產生很大問題,所以一般都需要在鍊錶最後乙個節點指向空指標

**:#include

#include

#include

#include

typedef struct l程式設計客棧node

lnode,*pnode;

//定義節點

pnode createlist()

//獲取鍊錶入口,也就是頭結點

pnode cur = phead;

while(1)

//讓當前節點(鍊錶的尾部)的後面加上讀取到資料的節點

cur->next=temp;

//讓當前的節點為鍊錶尾部

cur = temp;

//使最後乙個節點指向空,方便以後判斷

cur->next = null;

} return phead;

}//登入函式

int login(pnode head)

char name[10];

char pass[10];

printf("enter your name:");

scanf("%s",name);

printf("enter your password:");

scanf("%s",pass);

pnode temp = head->next;

while(temp)

temp = temp->next;

} printf("user not found");

getch();

}//寫入txt檔案,每一行存在乙個使用者

void writetofile(pnode head)

wh程式設計客棧ile(temp)

}//註冊使用者

void registeruser(pnode head)

else

pnode last = (pnode)malloc(sizeof(lnode));

temp->next = last;

temp = last;

} printf("enter your name:");

scanf("%s",temp->name);

printf("enter your password:");

scanf("%s",temp->pass);

temp->next=null;

}int menu()

int main()

system("cls");

} else if(2==choice)

else}}

執行結果

選單,比較簡陋,可以根據自己需求加東西

這次寫了選單程式設計客棧的迴圈

註冊登入

異常路徑(登入失敗)

本文標題: c語言利用鍊錶與檔案實現登入註冊功能

本文位址:

C語言鍊錶實現。

主攻c語言教程已經接近尾聲,越發激起了學習資料結構的興趣。學習資料結構不能沒有語言功底,要不然各種錯誤不知如何除錯,使用語言也不是十分自然。這兩樣應該是相得益彰的,學好一種語言,靈活運用,像說話一樣,然後掌握技巧。在資料結構中 鍊錶是非常重要的。下面是對聯表的實現以及基本的操作函式。還有一些細節歸納...

鍊錶的實現與操作 C語言實現

鍊錶的基本概念 表頭結點 鍊錶中的第乙個結點 包含指向第乙個資料元素的指標以及 鍊錶自身的一些資訊 資料結點 鍊錶中代表資料元素的結點 包含指向下乙個資料元素的指 針和資料元素的資訊 尾結點 鍊錶中的最後乙個資料結點 其下一元素指標為空 表示無 後繼 標頭檔案 ifndef linklist h d...

C語言鍊錶實現棧

鍊錶實現帶頭結點的棧,入棧用頭插法 環境codeblocks include include include typedef int elemtype typedef struct node node,linkstack 初始化棧 linkstack initstack linkstack s 入棧...