當前位置:首頁 » 編程語言 » 300行的c語言

300行的c語言

發布時間: 2023-06-16 04:34:34

㈠ 求c語言小程序源代碼,300行左右

黑白棋游戲
#include "graphics.h" /*圖形系統頭文件*/
#define LEFT 0x4b00 /*游標左鍵值*/
#define RIGHT 0x4d00 /*游標右鍵值*/
#define DOWN 0x5000 /*游標下鍵值*/
#define UP 0x4800 /*游標上鍵值*/
#define ESC 0x011b /* ESC鍵值*/
#define ENTER 0x1c0d /* 回車鍵值*/
int a[8][8]={0},key,score1,score2;/*具體分數以及按鍵與存放棋子的變數*/
char playone[3],playtwo[3];/*兩個人的得分轉換成字元串輸出*/
void playtoplay(void);/*人人對戰函數*/
void DrawQp(void);/*畫棋盤函數*/
void SetPlayColor(int x);/*設置棋子第一次的顏色*/
void MoveColor(int x,int y);/*恢復原來棋盤狀態*/
int QpChange(int x,int y,int z);/*判斷棋盤的變化*/
void DoScore(void);/*處理分數*/
void PrintScore(int n);/*輸出成績*/
void playWin(void);/*輸出勝利者信息*/
/******主函數*********/
void main(void)
{
int gd=DETECT,gr;
initgraph(&gd,&gr,"c:\\tc"); /*初始化圖形系統*/
DrawQp();/*畫棋盤*/
playtoplay();/*人人對戰*/
getch();
closegraph();/*關閉圖形系統*/
}
void DrawQp()/*畫棋盤*/
{
int i,j;
score1=score2=0;/*棋手一開始得分都為0*/
setbkcolor(BLUE);
for(i=100;i<=420;i+=40)
{
line(100,i,420,i);/*畫水平線*/
line(i,100,i,420); /*畫垂直線*/
}
setcolor(0);/*取消圓周圍的一圈東西*/
setfillstyle(SOLID_FILL,15);/*白色實體填凳顫充模式*/
fillellipse(500,200,15,15); /*在顯示得分的位置畫棋*/
setfillstyle(SOLID_FILL,8); /*黑色實體填充模式*/
fillellipse(500,300,15,15);
a[3][3]=a[4][4]=1;/*初始兩個黑棋*/
a[3][4]=a[4][3]=2;/*初始兩個白棋*/
setfillstyle(SOLID_FILL,WHITE);
fillellipse(120+3*40,120+3*40,15,15);
fillellipse(120+4*40,120+4*40,15,15);
setfillstyle(SOLID_FILL,8);
fillellipse(120+3*40,120+4*40,15,15);
fillellipse(120+4*40,120+3*40,15,15);
score1=score2=2; /*有棋後改變分數*/
DoScore();/*輸出開始分數*/
}
void playtoplay()/*人人對戰*/
{
int x,y,t=1,i,j,cc=0;
while(1)/*換棋好悄手走棋*/
{
x=120,y=80;/*每次棋子一開始出來的坐標,x為行坐標,y為列坐標*/
while(1) /*具體一個棋手走棋的過程*/
{
PrintScore(1);/*輸出棋手1的成績*/
PrintScore(2);/*輸出棋手2的成績*/
SetPlayColor(t);/*t變數是友粗渣用來判斷棋手所執棋子的顏色*/
fillellipse(x,y,15,15);
key=bioskey(0);/*接收按鍵*/
if(key==ESC)/*跳出遊戲*/
break;
else
if(key==ENTER)/*如果按鍵確定就可以跳出循環*/
{
if(y!=80&&a[(x-120)/40][(y-120)/40]!=1
&&a[(x-120)/40][(y-120)/40]!=2)/*如果落子位置沒有棋子*/
{
if(t%2==1)/*如果是棋手1移動*/
a[(x-120)/40][(y-120)/40]=1;
else/*否則棋手2移動*/
a[(x-120)/40][(y-120)/40]=2;
if(!QpChange(x,y,t))/*落子後判斷棋盤的變化*/
{
a[(x-120)/40][(y-120)/40]=0;/*恢復空格狀態*/
cc++;/*開始統計嘗試次數*/
if(cc>=64-score1-score2) /*如果嘗試超過空格數則停步*/
{
MoveColor(x,y);
fillellipse(x,y,15,15);
break;
}
else
continue;/*如果按鍵無效*/
}
DoScore();/*分數的改變*/
break;/*棋盤變化了,則輪對方走棋*/
}
else/*已經有棋子就繼續按鍵*/
continue;
}
else /*四個方向按鍵的判斷*/
if(key==LEFT&&x>120)/*左方向鍵*/
{
MoveColor(x,y);
fillellipse(x,y,15,15);
SetPlayColor(t);
x-=40;
fillellipse(x,y,15,15);
}
else
if(key==RIGHT&&x<400&&y>80)/*右方向鍵*/
{
MoveColor(x,y);
fillellipse(x,y,15,15);
SetPlayColor(t);
x+=40;
fillellipse(x,y,15,15);
}
else
if(key==UP&&y>120)/*上方向鍵*/
{
MoveColor(x,y);
fillellipse(x,y,15,15);
SetPlayColor(t);
y-=40;
fillellipse(x,y,15,15);
}
else
if(key==DOWN&&y<400)/*下方向鍵*/
{
MoveColor(x,y);
fillellipse(x,y,15,15);
SetPlayColor(t);
y+=40;
fillellipse(x,y,15,15);
}
}
if(key==ESC)/*結束游戲*/
break;
if((score1+score2)==64||score1==0||score2==0)/*格子已經占滿或一方棋子為0判斷勝負*/
{
playWin();/*輸出最後結果*/
break;
}
t=t%2+1; /*一方走後,改變棋子顏色即輪對方走*/
cc=0; /*計數值恢復為0*/
} /*endwhile*/
}
void SetPlayColor(int t)/*設置棋子顏色*/
{
if(t%2==1)
setfillstyle(SOLID_FILL,15);/*白色*/
else
setfillstyle(SOLID_FILL,8);/*灰色*/
}
void MoveColor(int x,int y)/*走了一步後恢復原來格子的狀態*/
{
if(y<100)/*如果是從起點出發就恢復藍色*/
setfillstyle(SOLID_FILL,BLUE);
else/*其他情況如果是1就恢復白色棋子,2恢復黑色棋子,或恢復藍色棋盤*/
switch(a[(x-120)/40][(y-120)/40])
{
case 1:
setfillstyle(SOLID_FILL,15);break; /*白色*/
case 2:
setfillstyle(SOLID_FILL,8);break; /*黑色*/
default:
setfillstyle(SOLID_FILL,BLUE); /*藍色*/
}
}
int QpChange(int x,int y,int t)/*判斷棋盤的變化*/
{
int i,j,k,kk,ii,jj,yes;
yes=0;
i=(x-120)/40; /*計算數組元素的行下標*/
j=(y-120)/40; /*計算數組元素的列下標*/
SetPlayColor(t);/*設置棋子變化的顏色*/
/*開始往8個方向判斷變化*/
if(j<6)/*往右邊*/
{
for(k=j+1;k<8;k++)
if(a[i][k]==a[i][j]||a[i][k]==0)/*遇到自己的棋子或空格結束*/
break;
if(a[i][k]!=0&&k<8)
{
for(kk=j+1;kk<k&&k<8;kk++)/*判斷右邊*/
{
a[i][kk]=a[i][j]; /*改變棋子顏色*/
fillellipse(120+i*40,120+kk*40,15,15);
}
if(kk!=j+1) /*條件成立則有棋子改變過顏色*/
yes=1;
}
}
if(j>1)/*判斷左邊*/
{
for(k=j-1;k>=0;k--)
if(a[i][k]==a[i][j]||!a[i][k])
break;
if(a[i][k]!=0&&k>=0)
{
for(kk=j-1;kk>k&&k>=0;kk--)
{
a[i][kk]=a[i][j];
fillellipse(120+i*40,120+kk*40,15,15);
}
if(kk!=j-1)
yes=1;
}
}
if(i<6)/*判斷下邊*/
{
for(k=i+1;k<8;k++)
if(a[k][j]==a[i][j]||!a[k][j])
break;
if(a[k][j]!=0&&k<8)
{
for(kk=i+1;kk<k&&k<8;kk++)
{
a[kk][j]=a[i][j];
fillellipse(120+kk*40,120+j*40,15,15);
}
if(kk!=i+1)
yes=1;
}
}
if(i>1)/*判斷上邊*/
{
for(k=i-1;k>=0;k--)
if(a[k][j]==a[i][j]||!a[k][j])
break;
if(a[k][j]!=0&&k>=0)
{
for(kk=i-1;kk>k&&k>=0;kk--)
{
a[kk][j]=a[i][j];
fillellipse(120+kk*40,120+j*40,15,15);
}
if(kk!=i-1)
yes=1;
}
}
if(i>1&&j<6)/*右上*/
{
for(k=i-1,kk=j+1;k>=0&&kk<8;k--,kk++)
if(a[k][kk]==a[i][j]||!a[k][kk])
break;
if(a[k][kk]&&k>=0&&kk<8)
{
for(ii=i-1,jj=j+1;ii>k&&k>=0;ii--,jj++)
{
a[ii][jj]=a[i][j];
fillellipse(120+ii*40,120+jj*40,15,15);
}
if(ii!=i-1)
yes=1;
}
}
if(i<6&&j>1)/*左下*/
{
for(k=i+1,kk=j-1;k<8&&kk>=0;k++,kk--)
if(a[k][kk]==a[i][j]||!a[k][kk])
break;
if(a[k][kk]!=0&&k<8&&kk>=0)
{
for(ii=i+1,jj=j-1;ii<k&&k<8;ii++,jj--)
{
a[ii][jj]=a[i][j];
fillellipse(120+ii*40,120+jj*40,15,15);
}
if(ii!=i+1)
yes=1;
}
}
if(i>1&&j>1)/*左上*/
{
for(k=i-1,kk=j-1;k>=0&&kk>=0;k--,kk--)
if(a[k][kk]==a[i][j]||!a[k][kk])
break;
if(a[k][kk]!=0&&k>=0&&kk>=0)
{
for(ii=i-1,jj=j-1;ii>k&&k>=0;ii--,jj--)
{
a[ii][jj]=a[i][j];
fillellipse(120+ii*40,120+jj*40,15,15);
}
if(ii!=i-1)
yes=1;
}
}
if(i<6&&j<6)/* 右下*/
{
for(k=i+1,kk=j+1;kk<8&&kk<8;k++,kk++)
if(a[k][kk]==a[i][j]||!a[k][kk])
break;
if(a[k][kk]!=0&&kk<8&&k<8)
{
for(ii=i+1,jj=j+1;ii<k&&k<8;ii++,jj++)
{
a[ii][jj]=a[i][j];
fillellipse(120+ii*40,120+jj*40,15,15);
}
if(ii!=i+1)
yes=1;
}
}
return yes;/*返回是否改變過棋子顏色的標記*/
}
void DoScore()/*處理分數*/
{
int i,j;
score1=score2=0;/*重新開始計分數*/
for(i=0;i<8;i++)
for(j=0;j<8;j++)
if(a[i][j]==1)/*分別統計兩個人的分數*/
score1++;
else
if(a[i][j]==2)
score2++;
}
void PrintScore(int playnum)/*輸出成績*/
{
if(playnum==1)/*清除以前的成績*/
{
setfillstyle(SOLID_FILL,BLUE);
bar(550,100,640,400);
}
setcolor(RED);
settextstyle(0,0,4);/*設置文本輸出樣式*/
if(playnum==1)/*判斷輸出哪個棋手的分,在不同的位置輸出*/
{
sprintf(playone,"%d",score1);
outtextxy(550,200,playone);
}
else
{
sprintf(playtwo,"%d",score2);
outtextxy(550,300,playtwo);
}
setcolor(0);
}
void playWin()/*輸出最後的勝利者結果*/
{
settextstyle(0,0,4);
setcolor(12);
if(score2>score1)/*開始判斷最後的結果*/
outtextxy(100,50,"black win!");
else
if(score2<score1)
outtextxy(100,50,"white win!");
else
outtextxy(60,50,"you all win!");
}

五子棋游戲
/*五子棋*/
#include<stdio.h>
#include<stdlib.h>
#include<graphics.h>
#include<bios.h>
#include<conio.h>

#define LEFT 0x4b00
#define RIGHT 0x4d00
#define DOWN 0x5000
#define UP 0x4800
#define ESC 0x011b
#define SPACE 0x3920

#define BILI 20
#define JZ 4
#define JS 3
#define N 19

int box[N][N];
int step_x,step_y ;
int key ;
int flag=1 ;

void draw_box();
void draw_cicle(int x,int y,int color);
void change();
void judgewho(int x,int y);
void judgekey();
int judgeresult(int x,int y);
void attentoin();

void attention()
{
char ch ;
window(1,1,80,25);
textbackground(LIGHTBLUE);
textcolor(YELLOW);
clrscr();
gotoxy(15,2);
printf("游戲操作規則:");
gotoxy(15,4);
printf("Play Rules:");
gotoxy(15,6);
printf("1、按左右上下方向鍵移動棋子");
gotoxy(15,8);
printf("1. Press Left,Right,Up,Down Key to move Piece");
gotoxy(15,10);
printf("2、按空格確定落棋子");
gotoxy(15,12);
printf("2. Press Space to place the Piece");
gotoxy(15,14);
printf("3、禁止在棋盤外按空格");
gotoxy(15,16);
printf("3. DO NOT press Space outside of the chessboard");
gotoxy(15,18);
printf("你是否接受上述的游戲規則(Y/N)");
gotoxy(15,20);
printf("Do you accept the above Playing Rules? [Y/N]:");
while(1)
{
gotoxy(60,20);
ch=getche();
if(ch=='Y'||ch=='y')
break ;
else if(ch=='N'||ch=='n')
{
window(1,1,80,25);
textbackground(BLACK);
textcolor(LIGHTGRAY);
clrscr();
exit(0);
}
gotoxy(51,12);
printf(" ");
}
}
void draw_box()
{
int x1,x2,y1,y2 ;
setbkcolor(LIGHTBLUE);
setcolor(YELLOW);
gotoxy(7,2);
printf("Left, Right, Up, Down KEY to move, Space to put, ESC-quit.");
for(x1=1,y1=1,y2=18;x1<=18;x1++)
line((x1+JZ)*BILI,(y1+JS)*BILI,(x1+JZ)*BILI,(y2+JS)*BILI);
for(x1=1,y1=1,x2=18;y1<=18;y1++)
line((x1+JZ)*BILI,(y1+JS)*BILI,(x2+JZ)*BILI,(y1+JS)*BILI);
for(x1=1;x1<=18;x1++)
for(y1=1;y1<=18;y1++)
box[x1][y1]=0 ;
}

void draw_circle(int x,int y,int color)
{
setcolor(color);
setlinestyle(SOLID_LINE,0,1);
x=(x+JZ)*BILI ;
y=(y+JS)*BILI ;
circle(x,y,8);
}

void judgekey()
{
int i ;
int j ;
switch(key)
{
case LEFT :

if(step_x-1<0)
break ;
else
{
for(i=step_x-1,j=step_y;i>=1;i--)
if(box[i][j]==0)
{
draw_circle(step_x,step_y,LIGHTBLUE);
break ;
}
if(i<1)break ;
step_x=i ;
judgewho(step_x,step_y);
break ;
}
case RIGHT :

if(step_x+1>18)
break ;
else
{
for(i=step_x+1,j=step_y;i<=18;i++)
if(box[i][j]==0)
{
draw_circle(step_x,step_y,LIGHTBLUE);
break ;
}
if(i>18)break ;
step_x=i ;
judgewho(step_x,step_y);
break ;
}
case DOWN :

if((step_y+1)>18)
break ;
else
{
for(i=step_x,j=step_y+1;j<=18;j++)
if(box[i][j]==0)
{
draw_circle(step_x,step_y,LIGHTBLUE);
break ;
}
if(j>18)break ;
step_y=j ;
judgewho(step_x,step_y);
break ;
}
case UP :

if((step_y-1)<0)
break ;
else
{
for(i=step_x,j=step_y-1;j>=1;j--)
if(box[i][j]==0)
{
draw_circle(step_x,step_y,LIGHTBLUE);
break ;
}
if(j<1)break ;
step_y=j ;
judgewho(step_x,step_y);
break ;
}
case ESC :
break ;

case SPACE :
if(step_x>=1&&step_x<=18&&step_y>=1&&step_y<=18)
{
if(box[step_x][step_y]==0)
{
box[step_x][step_y]=flag ;
if(judgeresult(step_x,step_y)==1)
{
sound(1000);
delay(1000);
nosound();
gotoxy(30,4);
if(flag==1)
{
setbkcolor(BLUE);
cleardevice();
setviewport(100,100,540,380,1);
/*定義一個圖形窗口*/
setfillstyle(1,2);
/*綠色以實填充*/
setcolor(YELLOW);
rectangle(0,0,439,279);
floodfill(50,50,14);
setcolor(12);
settextstyle(1,0,5);
/*三重筆劃字體, 水平放?5倍*/
outtextxy(20,20,"The White Win !");
setcolor(15);
settextstyle(3,0,5);
/*無襯筆劃字體, 水平放大5倍*/
outtextxy(120,120,"The White Win !");
setcolor(14);
settextstyle(2,0,8);
getch();
closegraph();
exit(0);
}
if(flag==2)
{
setbkcolor(BLUE);
cleardevice();
setviewport(100,100,540,380,1);
/*定義一個圖形窗口*/
setfillstyle(1,2);
/*綠色以實填充*/
setcolor(YELLOW);
rectangle(0,0,439,279);
floodfill(50,50,14);
setcolor(12);
settextstyle(1,0,8);
/*三重筆劃字體, 水平放大8倍*/
outtextxy(20,20,"The Red Win !");
setcolor(15);
settextstyle(3,0,5);
/*無襯筆劃字體, 水平放大5倍*/
outtextxy(120,120,"The Red Win !");
setcolor(14);
settextstyle(2,0,8);
getch();
closegraph();
exit(0);
}
}
change();
break ;
}
}
else
break ;
}
}

void change()
{
if(flag==1)
flag=2 ;
else
flag=1 ;
}

void judgewho(int x,int y)
{
if(flag==1)
draw_circle(x,y,15);
if(flag==2)
draw_circle(x,y,4);
}

int judgeresult(int x,int y)
{
int j,k,n1,n2 ;
while(1)
{
n1=0 ;
n2=0 ;
/*水平向左數*/
for(j=x,k=y;j>=1;j--)
{
if(box[j][k]==flag)
n1++;
else
break ;
}
/*水平向右數*/
for(j=x,k=y;j<=18;j++)
{
if(box[j][k]==flag)
n2++;
else
break ;
}
if(n1+n2-1>=5)
{
return(1);
break ;
}

/*垂直向上數*/
n1=0 ;
n2=0 ;
for(j=x,k=y;k>=1;k--)
{
if(box[j][k]==flag)
n1++;
else
break ;
}
/*垂直向下數*/
for(j=x,k=y;k<=18;k++)
{
if(box[j][k]==flag)
n2++;
else
break ;
}
if(n1+n2-1>=5)
{
return(1);
break ;
}

/*向左上方數*/
n1=0 ;
n2=0 ;
for(j=x,k=y;j>=1,k>=1;j--,k--)
{
if(box[j][k]==flag)
n1++;
else
break ;
}
/*向右下方數*/
for(j=x,k=y;j<=18,k<=18;j++,k++)
{
if(box[j][k]==flag)
n2++;
else
break ;
}
if(n1+n2-1>=5)
{
return(1);
break ;
}

/*向右上方數*/
n1=0 ;
n2=0 ;
for(j=x,k=y;j<=18,k>=1;j++,k--)
{
if(box[j][k]==flag)
n1++;
else
break ;
}
/*向左下方數*/
for(j=x,k=y;j>=1,k<=18;j--,k++)
{
if(box[j][k]==flag)
n2++;
else
break ;
}
if(n1+n2-1>=5)
{
return(1);
break ;
}
return(0);
break ;
}
}

void main()
{
int gdriver=VGA,gmode=VGAHI;
clrscr();
attention();
initgraph(&gdriver,&gmode,"c:\\tc");
/* setwritemode(XOR_PUT);*/
flag=1 ;
draw_box();
do
{
step_x=0 ;
step_y=0 ;
/*draw_circle(step_x,step_y,8); */
judgewho(step_x-1,step_y-1);
do
{
while(bioskey(1)==0);
key=bioskey(0);
judgekey();
}
while(key!=SPACE&&key!=ESC);
}
while(key!=ESC);
closegraph();
}

㈡ 求一個300行左右的簡單的c語言程序

#include<stdio.h>
#include<malloc.h>
#include<string.h>

#define LEN sizeof(struct record) /*對結構體長度進行宏定義*/

void menu();/*聲明菜單函數*/
struct record*insert(struct record *head);/*聲明添加函數 */
struct record*delet(struct record *head); /*聲明刪除函數 */
struct record*alter(struct record *head); /*聲明修改函數 */
void search(struct record *head); /*聲明查找函數*/
void show(struct record *head); /*聲明顯示函大源數*/

struct record *head; /*定義全局結構體指針變數*/
int n=0; /*定義全局變數*/

struct record /*聲明結構體*/
{
char number[10];
char name[20];
char phone[20];
char adress[40];
char postcode[10];
char e_mail[30];
struct record *next;
};

/******************************************************************************
* *
* 主函數 *
* *
*******************************************************************************/
main()
{
head=NULL;
menu();
rewind(stdin);
}

/******************************************************************************
* *
* 菜孝正單函數 *
* *
*******************************************************************************/
void menu()
{
int choice;
printf("\n\t\t******************** 主菜單 ********************");
printf("\n\t\t*********** 1-添加紀錄 2-查詢紀錄 ************");
printf("\n\t\t*********** 3-刪除紀錄 4-修改記錄 ************");
printf("\n\t\t*********** 5-顯示紀錄 6-退出系統 ************");
printf("\n\t\t************************************************"巧仿悔);
printf("\n\t\t請選擇:");
scanf("%d",&choice); rewind(stdin);
printf("\n");
switch (choice)
{
case 1:
head=insert(head);
rewind(stdin);
menu();
break;
case 2:
search(head);rewind(stdin);
menu();
break;
case 3:
head=delet(head);
rewind(stdin);
menu();
break;
case 4:
head=alter(head);
rewind(stdin);
menu();
break;
case 5:
show(head);
rewind(stdin);
menu();
break;
default:
printf("\n\t\t謝謝使用!!");
break;
}
}

/******************************************************************************
* *
* 添加函數 *
* *
*******************************************************************************/
struct record *insert(struct record *head)
{
struct record *pp,*p1,*p2;
pp=(struct record *)malloc(LEN);
printf("\n\t\t**************** 請輸入用戶信息 ****************\n");
printf("\n\t\t輸入序號:");
scanf("%s",pp->number); rewind(stdin);
printf("\n\t\t輸入姓名:");
scanf("%s",pp->name);rewind(stdin);
printf("\n\t\t輸入電話號碼:");
scanf("%s",pp->phone); rewind(stdin);
printf("\n\t\t輸入地址:");
scanf("%s",pp->adress); rewind(stdin);
printf("\n\t\t輸入郵編:");
scanf("%s",pp->postcode); rewind(stdin);
printf("\n\t\t輸入e-mail:");
scanf("%s",pp->e_mail); rewind(stdin);
if(head==NULL)/*在表頭插入1*/
{
head=pp;
pp->next=NULL;
}
else
{
p1=head;
while((strcmp(pp->number,p1->number)>0)&&(p1->next!=NULL))
{
p2=p1;
p1=p1->next;
}
if(strcmp(pp->number,p1->number)<=0)
{
if(head==p1)
head=pp; /*在表頭插入2*/
else
p2->next=pp;/*在表中插入*/
pp->next=p1;
}
else /*在表尾插入*/
{
p1->next=pp;
pp->next=NULL;
}
}
printf("\t添加成功!請繼續選擇功能鍵!\n\n");
n=n+1;
return(head);
}
/******************************************************************************
* *
* 刪除函數 *
* *
*******************************************************************************/
struct record*delet(struct record * head)
{
struct record *p1,*p2;
char number[10];
printf("\t請輸入要刪除用戶的序號number:");
scanf("%s",&number);rewind(stdin);
if(head==NULL)
{
printf("\n\t通訊錄無用戶信息記錄!!\n");
return(head);
}
p1=head;
while(strcmp(number,p1->number)!=0&&p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(strcmp(number,p1->number)==0)
{
if(p1==head)
{
head=p1->next;
printf("\t刪除成功!請繼續選擇功能鍵!\n\n");
}

else
{
p2=p1->next;
printf("\t已刪 除的用戶的序號為:%s\n",number);
printf("\t刪除成功!請繼續選擇功能鍵!\n\n");
}
n=n-1;
}
else printf("\t通訊錄無該用戶的信息記錄!\n ");
return(head);
}
/******************************************************************************
* *
* 查詢函數 *
* *
*******************************************************************************/
void search(struct record *head)
{
int a;
char f_name[20],f_number[10];
struct record *p1,*p2;
if(head==NULL)
{
printf("\t通訊錄無用戶信息記錄\n");
return;
}
else
{
printf("\t請你選擇你查找的方式:\n\n\t\t1:序號\n\t\t2:姓名\n");
printf("\t\t請選擇:");
scanf("%d",&a);rewind(stdin);
switch(a)
{case 1:
printf("\n\t請輸入要查找用戶的序號number:");
scanf("%s",&f_number);rewind(stdin);
p1=head;
while(strcmp(p1->number,f_number)!=0)
{
if(p1->next==NULL)
{
printf("\n\t通訊錄無此用戶信息記錄\n");
return;
}
else
{
p2=p1->next;
p1=p2;
}
}
printf("\n\t要查找用戶的基本信息為:\n");
printf("\t\t序號: %s\n\t\t姓名:%s\n\t\t電話號碼:%s",p1->number,p1->name,p1->phone);
printf("\n\t\t地址:%s\n\t\t郵編:%s\n\t\te_mail:%s\n",p1->adress,p1->postcode,p1->e_mail);
break;
case 2:
printf("\n\t請輸入要查找用戶的姓名name:");
scanf("%s",f_name);rewind(stdin);
p1=head;
while(strcmp(p1->name,f_name)!=0)
{
if(p1->next==NULL)
{
printf("\n\t通訊錄無此用戶信息記錄\n");
return;
}
else
{
p2=p1->next;
p1=p2;
}
}
printf("\n\t要查找用戶的基本信息為:\n");
printf("\t\t序號: %s\n\t\t姓名:%s\n\t\t電話號碼:%s",p1->number,p1->name,p1->phone);
printf("\n\t\t地址:%s\n\t\t郵編:%s\n\t\te_mail:%s",p1->adress,p1->postcode,p1->e_mail);
break;
}
}
}
/******************************************************************************
* *
* 顯示函數 *
* *
*******************************************************************************/
void show(struct record *head)
{
int i;
struct record *p1,*p2;
p1=head;
if(head==NULL)
{
printf("\t通訊錄無用戶信息記錄\n");
return;
}
else
{
for(i=1;i<=n;i++)
{
printf("\n\t第%d個用戶的基本信息為:",i);
printf("\n\t\t序號: %s 姓名:%s 電話號碼:%s \n\t\t地址:%s 郵編:%s e_mail:%s\n"
,p1->number,p1->name,p1->phone,p1->adress,p1->postcode,p1->e_mail);
p2=p1->next;
p1=p2;
}
}
}

/******************************************************************************
* *
* 修改函數 *
* *
*******************************************************************************/
struct record*alter(struct record*head)
{
struct record *p1,*p2;
int choice1;
char alter_number[10],alter_name[20],alter_phone[20],alter_adress[40],alter_postcode[10],alter_e_mail[30],choice2;
p1=head;
if(head==NULL)
{
printf("通訊錄無用戶信息記錄\n");
return(head);
}
printf("\t請輸入要修改的用戶的序號number:");
scanf("%s",alter_number);
rewind(stdin);
while(strcmp(p1->number,alter_number)!=0)
{
if(p1->next==NULL)
{
printf("\n\t通訊錄無此用戶信息記錄\n");
return(head);
}
else
{
p2=p1;
p1=p1->next;
}

}
if(strcmp(p1->number,alter_number)!=0)
{
printf("通訊錄無用戶信息記錄\n");
return(head);
}
else
{
printf("\t要修改的用戶的基本信息為:\n\t");
printf("\t序號: %s 姓名:%s 電話號碼:%s 地址:%s 郵編:%s e_mail:%s\n"
,p1->number,p1->name,p1->phone,p1->adress,p1->postcode,p1->e_mail);
}

while(1)
{
printf("\t你是否要修改的用戶的基本信息?(y&n)");
scanf("%c",&choice2);
rewind(stdin);
if(choice2=='y')
{
printf("\t請選擇你要修改的項目:\n\t");
printf("1:姓名 2:電話號碼 3:地址 4:郵編 5:e_mail\n");
printf("\t你選擇的序號為: ");
scanf("%d",&choice1);
rewind(stdin);
switch(choice1)
{case 1:printf("\t請輸入更改後的姓名");
scanf("%s",alter_name);rewind(stdin);
strcpy(p1->name,alter_name);
continue;
case 2:printf("\t請輸入更改後的電話號碼");
scanf("%s",alter_phone);rewind(stdin);
strcpy(p1->phone,alter_phone);
continue;
case 3:printf("\t請輸入更改後的地址");
scanf("%s",alter_adress);rewind(stdin);
strcpy(p1->adress,alter_adress);
continue;
case 4:printf("\t請輸入更改後的郵編");
scanf("%s",&alter_postcode);rewind(stdin);strcpy(p1->postcode,alter_postcode);
continue;
case 5:printf("\t請輸入更改後的e_mail");
scanf("%s",alter_e_mail);rewind(stdin);
strcpy(p1->e_mail,alter_e_mail);
continue;
}
printf("\n\t修改後用戶的基本信息為:\n\t");
printf("\t序號: %s 姓名:%s 電話號碼:%s 地址:%s 郵編:%s e_mail\n"
,p1->number,p1->name,p1->phone,p1->adress,p1->postcode,p1->e_mail);
}
else
{
printf("\n\t修改成功!!\n");
break;
}
}
return(head);
}

熱點內容
銳志哪個配置性價比最高 發布:2025-02-12 17:38:43 瀏覽:917
智能推送演算法 發布:2025-02-12 17:38:41 瀏覽:834
拍照上傳器 發布:2025-02-12 17:34:29 瀏覽:651
androidweb框架 發布:2025-02-12 17:32:45 瀏覽:75
安卓編程賀卡 發布:2025-02-12 17:32:44 瀏覽:837
php獲取資料庫的欄位 發布:2025-02-12 17:29:02 瀏覽:765
伺服器地址消失 發布:2025-02-12 17:23:36 瀏覽:950
後台執行php腳本 發布:2025-02-12 17:21:45 瀏覽:470
spring編程式事務 發布:2025-02-12 17:16:55 瀏覽:397
nginx禁止ip訪問 發布:2025-02-12 17:15:14 瀏覽:273