最近在幫考研跨考計算機的朋友學習c語言,from zero.
用單鏈表實現了乙個賬戶的管理系統。
麻雀雖小,五臟俱全。單鏈表的增刪改查(crud)全在裡面了,結構也很清晰,適合初學者學習鍊錶的基本操作。
#include
#include
#include
#define _crt_secure_no_deprecate
#define _crt_secure_no_warnings
#define buffer_size 100
#define max_account_username_length 20
#define max_account_password_length 20
typedef
struct _accountaccount;
enum choices
;account* accoutlinkedlist =
null
;void
printusage()
;void
createaccount()
;account*
findusername
(const
char
* username)
;void
retrieveaccount()
;void
updateaccount()
;void
deleteaccont()
;void
seeallacount()
;void
deleteallaccount()
;int
main
(int argc,
char
const
*ar**)
putchar
('\n');
printf
("press any key to continue.\n");
getchar()
;//eat the \n
getchar()
;//choke
}return0;
}void
printusage()
void
createaccount()
else
iter->next = a;
}printf
(,a->username,a->password );}
account*
findusername
(const
char
* username)
}return iter;
}void
retrieveaccount()
printf
("username[%s] setted the password to [%s].\n"
,iter->username,iter->password);}
void
updateaccount()
//update
printf
("old password is [%s], key in a new one, max length allowed = %d.\n"
,iter->password,max_account_password_length)
;scanf
("%s"
,buffer)
;strncpy
(iter->password,buffer,max_account_password_length)
;printf
("username[%s] setted the password to [%s].\n"
,iter->username,iter->password);}
void
deleteaccont()
}if(!isfound)
if(prev)
else
free
(iter)
;printf
("deleted!");
}void
seeallacount()
}void
deleteallaccount()
accoutlinkedlist =
null
;printf
("completed!\n");
}
一些測試
歡迎介面建立賬戶key in a number to select a menu...
1. create a account
2. retrieve password with a username
3. update password for a username
4. delete a existing account from the system
5. see all accounts in the system
6. delete all accounts from the system
獲取賬戶密碼create a account
the system won't check if the username already exists.
key in the username, max length allowed = 20.
sunkey in the password for user[sun],max length allowed = 20.
114514
press any key to continue.
更新賬戶密碼//存在
retrieve a account
key in the username, max length allowed = 20.
sunusername[sun] setted the password to [114514].
press any key to continue.
//不存在
retrieve a account
key in the username, max length allowed = 20.
otaku
username[otaku] does not exist.
press any key to continue.
刪除賬戶//存在
update a account
key in the username, max length allowed = 20.
sunold password is [114514], key in a new one, max length allowed = 20.
1919810
username[sun] setted the password to [1919810].
press any key to continue.
//不存在
update a account
key in the username, max length allowed = 20.
foobar
username[foobar] does not exist.
press any key to continue.
檢視所有賬戶//存在
update a account
key in the username, max length allowed = 20.
sundeleted!
press any key to continue.
//不存在
update a account
key in the username, max length allowed = 20.
sunusername[sun] does not exist.
press any key to continue.
刪除所有賬戶see all accounts
account #0
username:sun
password:114514
account #1
username:otaku
password:1919810
account #2
username:gnuisnotunix
password:wineisnotemulator
press any key to continue.
completed!
press any key to continue.
C語言編寫簡單的單鏈表(增刪改查)
純自己寫的,就是想試一下自己對指標 鍊錶內容的理解程度,沒有經過大量測試,只自己小小的測試了一下。include include includestruct node struct node creat void show struct node first bool insert struct n...
c語言 單鏈表的增刪改查(簡單版)
在學了鍊錶之後,自己也能寫出乙個簡單的鍊錶結構,這裡就將自己的 分享一下。如果發現有不足之處,歡迎指出。typedef struct dnode snode,ptr 這裡返回的是head,ptr initlink 初始化鍊錶並插入元素 向後插入 p head head head next free ...
hive的簡單增刪改查
安裝好hive後,開啟hadoop的目錄,可以看到,比之前多了乙個tmp資料夾,同時user目錄下也多了乙個hive資料夾 一 建表及插入 資料準備 在本地準備乙個word.txt檔案,內容如下 1 小明 2 小張 3 小美 4 小李 5 小宋 6 小曲 7 小樊 8 小曲 9 小樊 10 小明 1...