當前位置:首頁 » 操作系統 » c資料庫增刪改

c資料庫增刪改

發布時間: 2023-06-04 13:39:52

『壹』 c語言資料庫的增刪改查與鏈表的增刪改查有什麼區別

資料庫使用來存貯大數據的,鏈表是一種數據結構二者不是同一個概念,如果你想關閉之後數據能夠保存的話請使用資料庫或者文件,否則的話就用鏈表吧

『貳』 求教三層架構實現登錄並操縱資料庫增刪改查我是學C

所謂的三層架構就是將展示層、控制層和模型層層分開,通過介面的方式實現三層之間的解偶。展示層完成的試將業務信息展示給用戶並將業務數據從用戶收集,完成必要的合法性校驗後通過介面傳遞給控制層;
控制層呢則是根據業務數據完成嚴格的數據校驗,組裝必要的業務數據,將不同的業務請求提交不同的業務處理模塊(也就是模型層)完成業務處里,然後將模型層的返回數據轉換為展示層需要的數據,進行展示;
模型層就是進行業務處里的單元,完成各種業務邏輯的處理、資料庫的訪問等等;其實這一層可更細分為業務處里層和數據訪問層,也就是DAO層

明白了這些內容,你就應該明白你的需要了:
1、展示層:
(1)登錄頁面,請用戶輸入用戶明和密碼,必要時生成驗證碼(剛學,可以先不實現這個),簡單驗證後(比如數據長度等等)提交後將數據轉給控制層的登錄處理模塊;
(2)登錄成功頁面:用戶登錄成功展示的頁面(這是你的業務需要)
(3)登錄失敗頁面:密碼驗證失敗後的展示頁面,可以轉到登錄頁面並提示失敗,或者另建立新頁面;
2、控制層:
這里控制層只有一個處理模塊:登錄驗證。將展示層提交的數據進行業務邏輯驗證,比如:登錄名是什麼結構、不能包含什麼數據;密碼多長、需要什麼數據、不能包含什麼數據等等,都是你的業務規定;如果不成功直接返回展示層提示存在問題;通過後調用模型層的登錄處理模塊,進行業務處里;如果模型層處理成功,根據需要轉到成功頁面或者失敗頁面(展示層);必要時准備會話信息參數,以備後用;
3、模型層:
根據用戶登錄名叢書據庫中讀取用戶信息,檢驗密碼是不是正確(必要時後有密碼加密處理);用戶狀態是否正確,是否允許登錄等等信息校驗後將結果返回就可以了

『叄』 c語言 建立一個鏈表,實現增刪改查

下面是以前寫的一個關於鏈表的綜合操作,你可以看看,應該可以滿足你的要求。
/********************************************************************
created: 2009/09/15
created: 16:9:2009 17:20
filename: E:\dd\lianbiao\lianbiao.cpp
author:
purpose: 一個win32 的控制台程序
實現單項鏈表的數據刪除、插入、排序等功能
*********************************************************************/
#include <stdio.h>
#include "windows.h"
#include "malloc.h"

#define LEN sizeof(struct student)
#define NULL 0
#define N 5 //N為所要創建的鏈表的長度

int n = 0; //定義全局變數n,表示鏈表的節點個數
/*******************************************************************
Author/data: /2009/09/15
Description: 聲明一個結構體作為鏈表的節點.
tip: student 只是一個標簽,是不能聲明變數的
*********************************************************************/
struct student
{
int num;
float cj;
struct student *Pnext;
};

/*******************************************************************
Author/data: /2009/09/15
Description: 創建一個動態鏈表
參數: 返回鏈表的第一個節點的地址
x 為鏈表的長度
*********************************************************************/
struct student *pa(int x)
{
struct student *head;
struct student *p1,*p2;

// n = 0;
p1 = p2 = (struct student *)malloc(LEN); //開辟一個結構體內存
fflush(stdin); // 清除緩沖區數據 避免直接讀入緩沖區數據
scanf("%d,%f",&p1->num,&p1->cj);
head = NULL;
while(p1->Pnext != NULL)
{
n = n+1;
if(n == 1)
{
head = p1; // 鏈表的頭地址
}
else
{
p2->Pnext = p1; //鏈接鏈表數據
}
/* 判斷是否最後一個 */
if(n >= x)
{
p1->Pnext = NULL;
}
else
{
p2 = p1;
p1 = (struct student *)malloc(LEN);
fflush(stdin);
scanf("%d,%f",&p1->num,&p1->cj);
}
}
return(head);
}
/*******************************************************************
Author/data: /2009/09/15
Description: 輸出一個鏈表
參數: head為第一個節點的地址
*********************************************************************/
void print(struct student *head)
{
struct student *p;

int i = 0;
printf("\nNow,These %d records are:\n",n);
p = head;
if(head != NULL) // 如果鏈表不是空的,則進行數據輸出
{
do
{
printf("%d\t",i++);
printf("%5d %5.1f\n",p->num,p->cj); // 輸出鏈表數據
p = p->Pnext;
}while(p != NULL);
}
}
/*******************************************************************
Author/data: /2009/09/16
Description: 釋放動態鏈表的地址空間
參數: 鏈表的頭地址head
無返回值
*********************************************************************/
void freelinkspace(struct student *head)
{
struct student Ltemp;
Ltemp.Pnext = head->Pnext; // Ltemp 用來存放->next,避免空間被
// 釋放後,找不到下一個結點的地址
while(head->Pnext != NULL) // 判斷是否已經空間釋放到最後一個
{
free(head);
head = Ltemp.Pnext;
Ltemp.Pnext = head->Pnext;
}
free(head); // 釋放最後一個結點空間
}

/*******************************************************************
Author/data: /2009/09/15
Description: 刪除鏈表鏈表中的一個結點
參數: head 為第一個節點的地址
num 為要刪除結點的序號(head->num)
*********************************************************************/
struct student *del(struct student *head,int num)
{
struct student *p1,*p2;
p1 = head;
while(p1->num!=num && p1->Pnext!=NULL) // 尋找要刪除的結點
{
p2 = p1; // p2 存放刪除結點的前一個結點地址
p1 = p1->Pnext; // p1 存放要刪除的結點
}
if(num == p1->num) // 是否找到要刪除結點
{
if(p1 == head) // 刪除的是第一個結點
{
head = p1->Pnext;
}
else if(p1->Pnext == NULL) // 刪除的是最後一個結點
{
p2->Pnext = NULL;
}
else // 刪除中間的結點
{
p2->Pnext = p1->Pnext;
p1->Pnext = NULL;
}
printf("delete: %d\n",num);
n = n-1; // 鏈表長度 - 1
}
else
{
printf("%d not been found! \n",num);
}
delete(p1);
return(head);
}
/*******************************************************************
Author/data: /2009/09/16
Description: 添加一個結點到鏈表中
參數: head 為第一個結點的地址指針
stud 為要插入的結點的地址指針
*********************************************************************/
struct student *insert(struct student *head,struct student *stud)
{
struct student *p0,*p1,*p2;
p0 = stud;
p1 = head;
while(p0->num>p1->num && p1->Pnext!=NULL) // 找到添加結點的位置
{
p2 = p1; // p2 存放要添加的前一個結點的地址
p1 = p1->Pnext; // p1 存放要添加的後一個結點的地址
}
if(p0->num<=p1->num && p1->Pnext!=NULL)
{
if(p1 == head) // 添加結點到第一個位置
{
p0->Pnext = p1;
head = p0;
}
else
{
p2->Pnext = p0;
p0->Pnext = p1;
}
}
else // 添加結點到最後一個位置
{

p1->Pnext = p0;
p0->Pnext = NULL;
}
n = n+1; // 結點數目 + 1
return(head);
}
/*******************************************************************
Author/data: /2009/09/16
Description: 鏈表的重新排序===按照.num(不能重復)的大小從小到大排
列鏈表數據
參數: head 接收鏈表第一個節點的地址指針
返回值為新生成鏈表的第一個節點的地址指針
*********************************************************************/
struct student *linkpaix(struct student *head)
{
struct student *stemp,*ltemp,*shead,*head_h; /* */
struct student *p,*q; /* 申請兩個鏈表指針,用來儲存鏈表交換過
程的中間值 */
head_h = head;
ltemp = head;

p = (struct student *) malloc(LEN);
q = (struct student *) malloc(LEN); /* 為p,q開辟動態存儲空間 */

/* -==== 先將鏈表的第一個數據與其他數據比較 ====- */
while(head->Pnext != NULL)
{
shead = head;
head = head->Pnext;
if(ltemp->num > head->num)
{
if(ltemp == shead)
{
ltemp ->Pnext = head ->Pnext;
head ->Pnext = ltemp;
}
else
{
p->Pnext = head ->Pnext;
q->Pnext = ltemp ->Pnext;
head ->Pnext = q->Pnext;
shead ->Pnext = ltemp;
ltemp ->Pnext = p->Pnext;
}
head_h = head;
head = ltemp;
ltemp = head_h;
}

}
/* -==== 先將鏈表的第一個數據與其他數據比較 ====- */

/* -==== 比較鏈表第一個以外的數據 ====- */
while(ltemp ->Pnext != NULL)
{
stemp = ltemp;
ltemp = ltemp ->Pnext;
head = ltemp;
while(head->Pnext != NULL)
{
shead = head;
head = head->Pnext;
if(ltemp->num > head->num)
{
if(ltemp == shead)
{
p->Pnext = head ->Pnext;
stemp ->Pnext = head;
head ->Pnext = ltemp;
ltemp ->Pnext = p->Pnext;
}
else
{
p->Pnext = head ->Pnext;
q->Pnext = ltemp ->Pnext;
stemp ->Pnext = head;
head ->Pnext = q->Pnext;
shead ->Pnext = ltemp;
ltemp ->Pnext = p->Pnext;
}
head = ltemp;
ltemp = stemp ->Pnext;
}
}

}
/* -==== 比較鏈表第一個以外的數據 ====- */

free(p);
free(q); // 釋放p,q的動態存儲空間
return(head_h);
}

/*******************************************************************
Author/data: /2009/09/15
Description: 主函數
參數:
*********************************************************************/
void main()
{
struct student *phead,*pins; // 定義2個鏈表指針
int delnum, selflog,flog_a = 1,Nf = 1; // 要刪除的對象id
char delflog ; // 刪除標志y/n
char insflog, flog_nx = 'n';
char flog_free ; // 釋放標志
/* === 輸入N個數據 === N 為定值
printf("please input %d numbers:\n",N);
phead = pa(N); // 創建一個動態鏈表,並賦值
print(phead); // 輸出鏈表數據
*/

/* === 輸入Nx個數據 === Nx 為輸入值 === */
int Nx; // Nx 想要輸入的鏈表長度
printf("How long do you want establish? \t");
fflush(stdin);
scanf("%d",&Nx);
/* -== 判斷創建的是否是一個空鏈表 ==- */
while(Nx == 0)
{
printf("您要創建的是一個空鏈表,是否確定?y/n \t");
fflush(stdin);
scanf("%c",&flog_nx);
if(flog_nx == 'n')
{
printf("How long do you want input?\t");
fflush(stdin);
scanf("%d",&Nx);
}
else if(flog_nx == 'y') goto endl;
else
{
printf("wrong input!\n");
printf("How long do you want input?\t");
fflush(stdin);
scanf("%d",&Nx);
}
}

printf("please input %d numbers: ",Nx);
printf("如:1,3 兩個數中間以,隔開\n");
phead = pa(Nx); // 創建一個動態鏈表,並賦值
print(phead); // 輸出鏈表數據

/* -== 鏈表操作 ==- */
while(flog_a)
{
if(phead == NULL) {printf("鏈表已空,無法操作\n"); flog_a = 0; break;}
printf("\n操作\n1:\t插入數據\n2:\t刪除數據\n3:\t排序\n4:\t清屏\n5:\t輸出現在的鏈表數據\n0:\texit\n");
printf("\nPlease input:\t");
fflush(stdin);
if(scanf("%d",&selflog)) // select flog 選擇項
switch(selflog)
{
case 1 :
/* ====== 插入數據到鏈表 ====== */
printf("insert someone? y/n\t");
fflush(stdin);
scanf("%c",&insflog);
while(insflog != 'n')
{
while(insflog != 'y'&& insflog != 'n')
{
printf("wrnong input,please input again. \n");
printf("another one? y/n\t");
fflush(stdin);
scanf("%c",&insflog);
}
printf("please input the date:\n");
pins = (struct student *)malloc(LEN);
fflush(stdin);
scanf("%d,%f",&pins->num,&pins->cj);
phead = insert(phead,pins);
print(phead);

printf("another one? y/n\t");
fflush(stdin);
scanf("%c",&insflog);
while(insflog != 'y'&& insflog != 'n')
{
printf("wrnong input,please input again. \n");
printf("another one? y/n\t");
fflush(stdin);
scanf("%c",&insflog);
}
}
/* ====== 插入數據到鏈表 ====== */
break;

case 2 :
/* ====== 刪除鏈表中的數據 ====== */
printf("del someone? y/n\t");
fflush(stdin);
scanf("%c",&delflog);
while(delflog != 'n' && phead != NULL)
{
while(delflog != 'y'&& delflog != 'n')
{
printf("wrnong input,please input again. \n");
printf("del someone? y/n\t");
fflush(stdin);
scanf("%c",&delflog);
}
printf("please input the student what you want del:\n");
fflush(stdin);
scanf("%d",&delnum);
phead = del(phead,delnum);
print(phead);

printf("another one? y/n\t");
fflush(stdin);
scanf("%c",&delflog);
if((n+1)==0)
{
printf("There is no more num could be del!\n");
break;
}
}
/* ====== 刪除鏈表中的數據 ====== */
break;

case 3 :
/* ====== 排列鏈表數據 ====== */
printf("\n排序之後:");
phead = linkpaix(phead);
print(phead); // 排序該數據鏈表
/* ====== 排列鏈表數據 ====== */
break;
case 4 :// clrscr();
system("cls");
break;

case 5 : print(phead); break;
case 0 : flog_a = 0 ; break; /* 退出 */

default : printf("wrong input\nPlease input again");
break;
}
else printf("非法輸入!\n");
}
endl: while(1)
{
if(Nx == 0)
{
printf("Can't establish the link!\n");
break;
}
printf("\n保留數據?y/n\t"); // 是否釋放地址空間
fflush(stdin);
scanf("%c",&flog_free);
if(flog_free == 'y')
{
break;
}
else if(flog_free == 'n')
{
freelinkspace(phead);
break;
}
else
{
printf("wrong input!\n");
}
}

printf("OVER!\nGOOD LUCK!\n");
}

『肆』 C語言數組 增刪改查 刪改兩個程序怎麼寫

這行代碼:數組=(結構記錄*)malloc的(的sizeof(結構記錄)* NUM); 是應用的內存結構記錄類型,你定義為int *,所以詮釋*數組轉換成結構記錄*數組,另有界定者外Num和我不記錄定義放在一起,否則,同一類型和記錄,是獨立的定義為:整型數,scanf函數(「%c」的,與數組[I]系數);改革為scanf函數(在「%f」,&陣列由[i]系數).

『伍』 基於結構體的C語言動態數組增刪改查演算法

實現步驟:1建立自定義結構體,2建立一個結構體指針數組,3實現添加(重新開辟一段內存給新元素,重新指定數組大小,添加元素指針到數組),4實現刪除(獲取需要刪除的項,釋放結構體指針,重新指定數組大小,如果刪除的是不是最後一個元素還需要移動元素),5修改元素內容 額 前幾步都編好了的話 這步應該就沒什麼問題了 提示***主要函數,malloc,free

熱點內容
安卓手機可以用的谷歌叫什麼 發布:2024-04-25 12:05:57 瀏覽:942
linux改變用戶所屬組 發布:2024-04-25 11:50:33 瀏覽:469
rsa加密演算法java代碼 發布:2024-04-25 11:40:07 瀏覽:883
如何改變拉桿箱上的初始密碼 發布:2024-04-25 11:17:23 瀏覽:799
內網掛代理虛擬機如何配置網卡 發布:2024-04-25 11:15:06 瀏覽:687
明日之後緩存怎麼清理 發布:2024-04-25 11:14:56 瀏覽:205
華為mate30怎麼退回安卓版 發布:2024-04-25 11:08:49 瀏覽:898
安卓新機使用前要注意什麼 發布:2024-04-25 11:03:46 瀏覽:811
藍鳥哪個配置有按摩 發布:2024-04-25 10:53:24 瀏覽:940
崩壞3要求什麼蘋果手機配置 發布:2024-04-25 10:36:59 瀏覽:142