最近2018中文字幕在日韩欧美国产成人片_国产日韩精品一区二区在线_在线观看成年美女黄网色视频_国产精品一区三区五区_国产精彩刺激乱对白_看黄色黄大色黄片免费_人人超碰自拍cao_国产高清av在线_亚洲精品电影av_日韩美女尤物视频网站

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
c語言通訊錄的函數(shù)流程 用c語言編寫簡單的通訊錄

用C語言做通訊錄

這看你是怎樣定義的了。如果你50個同學(xué)是用結(jié)構(gòu)體來定義的話就比較容易實(shí)現(xiàn)。用二維數(shù)組的話,就比較麻煩。

在洞頭等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供網(wǎng)站設(shè)計、成都做網(wǎng)站 網(wǎng)站設(shè)計制作按需求定制設(shè)計,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),成都品牌網(wǎng)站建設(shè),營銷型網(wǎng)站,外貿(mào)網(wǎng)站制作,洞頭網(wǎng)站建設(shè)費(fèi)用合理。

查找名字可以用strcmp(輸入的名字,編好的名字)==0如果相等,就等于查找到你輸入的名字了。記錄它的下標(biāo),再輸出它的聯(lián)系方式。

下面是一個比較完整的通訊錄代碼,你參考一下啦。(看到專家兩個字,我真沒資格去回答你了,汗)

/*10.3.2源程序*/

/******頭文件(.h)***********/

#include "stdio.h" /*I/O函數(shù)*/

#include "stdlib.h" /*標(biāo)準(zhǔn)庫函數(shù)*/

#include "string.h"/*字符串函數(shù)*/

#include "ctype.h" /*字符操作函數(shù)*/

#define M 50 /*定義常數(shù)表示記錄數(shù)*/

typedef struct /*定義數(shù)據(jù)結(jié)構(gòu)*/

{

char name[20]; /*姓名*/

char units[30]; /*單位*/

char tele[10]; /*電話*/

}ADDRESS;

/******以下是函數(shù)原型*******/

int enter(ADDRESS t[]); /*輸入記錄*/

void list(ADDRESS t[],int n); /*顯示記錄*/

void search(ADDRESS t[],int n); /*按姓名查找顯示記錄*/

int delete(ADDRESS t[],int n); /*刪除記錄*/

int add(ADDRESS t[],int n); /*插入記錄*/

void save(ADDRESS t[],int n); /*記錄保存為文件*/

int load(ADDRESS t[]); /*從文件中讀記錄*/

void display(ADDRESS t[]); /*按序號查找顯示記錄*/

void sort(ADDRESS t[],int n); /*按姓名排序*/

void qseek(ADDRESS t[],int n); /*快速查找記錄*/

void copy(); /*文件復(fù)制*/

void print(ADDRESS temp); /*顯示單條記錄*/

int find(ADDRESS t[],int n,char *s) ; /*查找函數(shù)*/

int menu_select(); /*主菜單函數(shù)*/

/******主函數(shù)開始*******/

main()

{

int i;

ADDRESS adr[M]; /*定義結(jié)構(gòu)體數(shù)組*/

int length; /*保存記錄長度*/

clrscr(); /*清屏*/

for()/*無限循環(huán)*/

{

switch(menu_select()) /*調(diào)用主菜單函數(shù),返回值整數(shù)作開關(guān)語句的條件*/

{

case 0:length=enter(adr);break;/*輸入記錄*/

case 1:list(adr,length);break; /*顯示全部記錄*/

case 2:search(adr,length);break; /*查找記錄*/

case 3:length=delete(adr,length);break; /*刪除記錄*/

case 4:length=add(adr,length); break; /*插入記錄*/

case 5:save(adr,length);break; /*保存文件*/

case 6:length=load(adr); break; /*讀文件*/

case 7:display(adr);break; /*按序號顯示記錄*/

case 8:sort(adr,length);break; /*按姓名排序*/

case 9:qseek(adr,length);break; /*快速查找記錄*/

case 10:copy();break; /*復(fù)制文件*/

case 11:exit(0); /*如返回值為11則程序結(jié)束*/

}

}

}

/*菜單函數(shù),函數(shù)返回值為整數(shù),代表所選的菜單項(xiàng)*/

menu_select()

{

char s[80];

int c;

gotoxy(1,25);/*將光標(biāo)定為在第25行,第1列*/

printf("press any key enter menu......\n");/*提示壓任意鍵繼續(xù)*/

getch(); /*讀入任意字符*/

clrscr(); /*清屏*/

gotoxy(1,1);

printf("********************MENU*********************\n\n");

printf(" 0. Enter record\n");

printf(" 1. List the file\n");

printf(" 2. Search record on name\n");

printf(" 3. Delete a record\n");

printf(" 4. add record \n");

printf(" 5. Save the file\n");

printf(" 6. Load the file\n");

printf(" 7. display record on order\n");

printf(" 8. sort to make new file\n");

printf(" 9. Quick seek record\n");

printf(" 10. copy the file to new file\n");

printf(" 11. Quit\n");

printf("***********************************************\n");

do{

printf("\n Enter you choice(0~11):"); /*提示輸入選項(xiàng)*/

scanf("%s",s); /*輸入選擇項(xiàng)*/

c=atoi(s); /*將輸入的字符串轉(zhuǎn)化為整型數(shù)*/

}while(c11); /*選擇項(xiàng)不在0~11之間重輸*/

return c; /*返回選擇項(xiàng),主程序根據(jù)該數(shù)調(diào)用相應(yīng)的函數(shù)*/

}

/***輸入記錄,形參為結(jié)構(gòu)體數(shù)組,函數(shù)值返回類型為整型表示記錄長度*/

int enter(ADDRESS t[])

{

int i,n;

char *s;

clrscr(); /*清屏*/

printf("\nplease input num \n"); /*提示信息*/

scanf("%d",n); /*輸入記錄數(shù)*/

printf("please input record \n"); /*提示輸入記錄*/

printf("name unit telephone\n");

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

for(i=0;in;i++)

{

scanf("%s%s%s",t[i].name,t[i].units,t[i].tele); /*輸入記錄*/

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

}

return n; /*返回記錄條數(shù)*/

}

/*顯示記錄,參數(shù)為記錄數(shù)組和記錄條數(shù)*/

void list(ADDRESS t[],int n)

{

int i;

clrscr();

printf("\n\n*******************ADDRESS******************\n");

printf("name unit telephone\n");

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

for(i=0;in;i++)

printf("%-20s%-30s%-10s\n",t[i].name,t[i].units,t[i].tele);

if((i+1)%10==0) /*判斷輸出是否達(dá)到10條記錄*/

{

printf("Press any key continue...\n"); /*提示信息*/

getch(); /*壓任意鍵繼續(xù)*/

}

printf("************************end*******************\n");

}

/*查找記錄*/

void search(ADDRESS t[],int n)

{

char s[20]; /*保存待查找姓名字符串*/

int i; /*保存查找到結(jié)點(diǎn)的序號*/

clrscr(); /*清屏*/

printf("please search name\n");

scanf("%s",s); /*輸入待查找姓名*/

i=find(t,n,s); /*調(diào)用find函數(shù),得到一個整數(shù)*/

if(in-1) /*如果整數(shù)i值大于n-1,說明沒找到*/

printf("not found\n");

else

print(t[i]); /*找到,調(diào)用顯示函數(shù)顯示記錄*/

}

/*顯示指定的一條記錄*/

void print(ADDRESS temp)

{

clrscr();

printf("\n\n********************************************\n");

printf("name unit telephone\n");

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

printf("%-20s%-30s%-10s\n",temp.name,temp.units,temp.tele);

printf("**********************end***********************\n");

}

/*查找函數(shù),參數(shù)為記錄數(shù)組和記錄條數(shù)以及姓名s */

int find(ADDRESS t[],int n,char *s)

{

int i;

for(i=0;in;i++)/*從第一條記錄開始,直到最后一條*/

{

if(strcmp(s,t[i].name)==0) /*記錄中的姓名和待比較的姓名是否相等*/

return i; /*相等,則返回該記錄的下標(biāo)號,程序提前結(jié)結(jié)束*/

}

return i; /*返回i值*/

}

/*刪除函數(shù),參數(shù)為記錄數(shù)組和記錄條數(shù)*/

int delete(ADDRESS t[],int n)

{

char s[20]; /*要刪除記錄的姓名*/

int ch=0;

int i,j;

printf("please deleted name\n"); /*提示信息*/

scanf("%s",s);/*輸入姓名*/

i=find(t,n,s); /*調(diào)用find函數(shù)*/

if(in-1) /*如果in-1超過了數(shù)組的長度*/

printf("no found not deleted\n"); /*顯示沒找到要刪除的記錄*/

else

{

print(t[i]); /*調(diào)用輸出函數(shù)顯示該條記錄信息*/

printf("Are you sure delete it(1/0)\n"); /*確認(rèn)是否要刪除*/

scanf("%d",ch); /*輸入一個整數(shù)0或1*/

if(ch==1) /*如果確認(rèn)刪除整數(shù)為1*/

{

for(j=i+1;jn;j++) /*刪除該記錄,實(shí)際后續(xù)記錄前移*/

{

strcpy(t[j-1].name,t[j].name); /*將后一條記錄的姓名拷貝到前一條*/

strcpy(t[j-1].units,t[j].units); /*將后一條記錄的單位拷貝到前一條*/

strcpy(t[j-1].tele,t[j].tele); /*將后一條記錄的電話拷貝到前一條*/

}

n--; /*記錄數(shù)減1*/

}

}

return n; /*返回記錄數(shù)*/

}

/*插入記錄函數(shù),參數(shù)為結(jié)構(gòu)體數(shù)組和記錄數(shù)*/

int add(ADDRESS t[],int n)/*插入函數(shù),參數(shù)為結(jié)構(gòu)體數(shù)組和記錄數(shù)*/

{

ADDRESS temp; /*新插入記錄信息*/

int i,j;

char s[20]; /*確定插入在哪個記錄之前*/

printf("please input record\n");

printf("************************************************\n");

printf("name unit telephone\n");

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

scanf("%s%s%s",temp.name,temp.units,temp.tele); /*輸入插入信息*/

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

printf("please input locate name \n");

scanf("%s",s); /*輸入插入位置的姓名*/

i=find(t,n,s); /*調(diào)用find,確定插入位置*/

for(j=n-1;j=i;j--) /*從最后一個結(jié)點(diǎn)開始向后移動一條*/

{

strcpy(t[j+1].name,t[j].name); /*當(dāng)前記錄的姓名拷貝到后一條*/

strcpy(t[j+1].units,t[j].units); /*當(dāng)前記錄的單位拷貝到后一條*/

strcpy(t[j+1].tele,t[j].tele); /*當(dāng)前記錄的電話拷貝到后一條*/

}

strcpy(t[i].name,temp.name); /*將新插入記錄的姓名拷貝到第i個位置*/

strcpy(t[i].units,temp.units); /*將新插入記錄的單位拷貝到第i個位置*/

strcpy(t[i].tele,temp.tele); /*將新插入記錄的電話拷貝到第i個位置*/

n++; /*記錄數(shù)加1*/

return n; /*返回記錄數(shù)*/

}

/*保存函數(shù),參數(shù)為結(jié)構(gòu)體數(shù)組和記錄數(shù)*/

void save(ADDRESS t[],int n)

{

int i;

FILE *fp; /*指向文件的指針*/

if((fp=fopen("record.txt","wb"))==NULL) /*打開文件,并判斷打開是否正常*/

{

printf("can not open file\n");/*沒打開*/

exit(1); /*退出*/

}

printf("\nSaving file\n"); /*輸出提示信息*/

fprintf(fp,"%d",n); /*將記錄數(shù)寫入文件*/

fprintf(fp,"\r\n"); /*將換行符號寫入文件*/

for(i=0;in;i++)

{

fprintf(fp,"%-20s%-30s%-10s",t[i].name,t[i].units,t[i].tele);/*格式寫入記錄*/

fprintf(fp,"\r\n"); /*將換行符號寫入文件*/

}

fclose(fp);/*關(guān)閉文件*/

printf("****save success***\n"); /*顯示保存成功*/

}

/*讀入函數(shù),參數(shù)為結(jié)構(gòu)體數(shù)組*/

int load(ADDRESS t[])

{

int i,n;

FILE *fp; /*指向文件的指針*/

if((fp=fopen("record.txt","rb"))==NULL)/*打開文件*/

{

printf("can not open file\n"); /*不能打開*/

exit(1); /*退出*/

}

fscanf(fp,"%d",n); /*讀入記錄數(shù)*/

for(i=0;in;i++)

fscanf(fp,"%20s%30s%10s",t[i].name,t[i].units,t[i].tele); /*按格式讀入記錄*/

fclose(fp); /*關(guān)閉文件*/

printf("You have success read data from file!!!\n"); /*顯示保存成功*/

return n; /*返回記錄數(shù)*/

}

/*按序號顯示記錄函數(shù)*/

void display(ADDRESS t[])

{

int id,n;

FILE *fp; /*指向文件的指針*/

if((fp=fopen("record.txt","rb"))==NULL) /*打開文件*/

{

printf("can not open file\n"); /*不能打開文件*/

exit(1); /*退出*/

}

printf("Enter order number...\n"); /*顯示信息*/

scanf("%d",id); /*輸入序號*/

fscanf(fp,"%d",n); /*從文件讀入記錄數(shù)*/

if(id=0idn) /*判斷序號是否在記錄范圍內(nèi)*/

{

fseek(fp,(id-1)*sizeof(ADDRESS),1); /*移動文件指針到該記錄位置*/

print(t[id]); /*調(diào)用輸出函數(shù)顯示該記錄*/

printf("\r\n");

}

else

printf("no %d number record!!!\n ",id); /*如果序號不合理顯示信息*/

fclose(fp); /*關(guān)閉文件*/

}

/*排序函數(shù),參數(shù)為結(jié)構(gòu)體數(shù)組和記錄數(shù)*/

void sort(ADDRESS t[],int n)

{

int i,j,flag;

ADDRESS temp; /*臨時變量做交換數(shù)據(jù)用*/

for(i=0;in;i++)

{

flag=0; /*設(shè)標(biāo)志判斷是否發(fā)生過交換*/

for(j=0;jn-1;j++)

if((strcmp(t[j].name,t[j+1].name))0) /*比較大小*/

{

flag=1;

strcpy(temp.name,t[j].name); /*交換記錄*/

strcpy(temp.units,t[j].units);

strcpy(temp.tele,t[j].tele);

strcpy(t[j].name,t[j+1].name);

strcpy(t[j].units,t[j+1].units);

strcpy(t[j].tele,t[j+1].tele);

strcpy(t[j+1].name,temp.name);

strcpy(t[j+1].units,temp.units);

strcpy(t[j+1].tele,temp.tele);

}

if(flag==0)break; /*如果標(biāo)志為0,說明沒有發(fā)生過交換循環(huán)結(jié)束*/

}

printf("sort sucess!!!\n"); /*顯示排序成功*/

}

/*快速查找,參數(shù)為結(jié)構(gòu)體數(shù)組和記錄數(shù)*/

void qseek(ADDRESS t[],int n)

{

char s[20];

int l,r,m;

printf("\nPlease sort before qseek!\n"); /*提示確認(rèn)在查找之前,記錄是否已排序*/

printf("please enter name for qseek\n"); /*提示輸入*/

scanf("%s",s); /*輸入待查找的姓名*/

l=0;r=n-1; /*設(shè)置左邊界與右邊界的初值*/

while(l=r) /*當(dāng)左邊界=右邊界時*/

{

m=(l+r)/2; /*計算中間位置*/

if(strcmp(t[m].name,s)==0) /*與中間結(jié)點(diǎn)姓名字段做比較判是否相等*/

{

print(t[m]); /*如果相等,則調(diào)用print函數(shù)顯示記錄信息*/

return ; /*返回*/

}

if(strcmp(t[m].name,s)0) /*如果中間結(jié)點(diǎn)小*/

l=m+1; /*修改左邊界*/

else

r=m-1; /*否則,中間結(jié)點(diǎn)大,修改右邊界*/

}

if(lr) /*如果左邊界大于右邊界時*/

printf("not found\n"); /*顯示沒找到*/

}

/*復(fù)制文件*/

void copy()

{

char outfile[20]; /*目標(biāo)文件名*/

int i,n;

ADDRESS temp[M]; /*定義臨時變量*/

FILE *sfp,*tfp; /*定義指向文件的指針*/

clrscr();/*清屏*/

if((sfp=fopen("record.txt","rb"))==NULL) /*打開記錄文件*/

{

printf("can not open file\n"); /*顯示不能打開文件信息*/

exit(1); /*退出*/

}

printf("Enter outfile name,for example c:\\f1\\te.txt:\n"); /*提示信息*/

scanf("%s",outfile); /*輸入目標(biāo)文件名*/

if((tfp=fopen(outfile,"wb"))==NULL) /*打開目標(biāo)文件*/

{

printf("can not open file\n"); /*顯示不能打開文件信息*/

exit(1); /*退出*/

}

fscanf(sfp,"%d",n); /*讀出文件記錄數(shù)*/

fprintf(tfp,"%d",n);/*寫入目標(biāo)文件數(shù)*/

fprintf(tfp,"\r\n"); /*寫入換行符*/

for(i=0;in;i++)

{

fscanf(sfp,"%20s%30s%10s\n",temp[i].name,temp[i].units,

temp[i].tele); /*讀入記錄*/

fprintf(tfp,"%-20s%-30s%-10s\n",temp[i].name,

temp[i].units,temp[i].tele); /*寫入記錄*/

fprintf(tfp,"\r\n"); /*寫入換行符*/

}

fclose(sfp); /*關(guān)閉源文件*/

fclose(tfp); /*關(guān)閉目標(biāo)文件*/

printf("you have success copy file!!!\n"); /*顯示復(fù)制成功*/

}

好好參考一下啦,可能有些函數(shù)你還沒學(xué)到,找找書就行了。

編寫C語言一個通訊錄程序

這是我以前寫的課程設(shè)計,

電子通訊錄功能如下:

Function choose

1.Read

2.Append

3.Delete

4.Search

5.Save and exit

6.Quit

說明:上圖是電子通訊錄的主菜單,利用它,將能夠輕松地錄入一個朋友的電話號

碼,通訊地址和出生日期,而且它還提供了檢索和刪除功能。在后面還將提供按生

日先后排序的功能,這些都有助于該通訊錄的管理。

電子通訊錄是采用線性表作為程序的基本結(jié)構(gòu)的。

設(shè)計思想:

1。用順序表設(shè)計電子通訊錄的結(jié)構(gòu)

為了表示較為復(fù)雜的數(shù)據(jù)內(nèi)容,一般用結(jié)構(gòu)這種數(shù)據(jù)類型,第一步就是在結(jié)構(gòu)中定

義所需要的各項(xiàng)信息。

一般的通訊錄都包括姓名,性別,出生年月,通訊地址和聯(lián)系電話這幾項(xiàng),而

在這幾項(xiàng)中,出生年月又包括年份,月份和日期三項(xiàng),通訊地址包括郵編和家庭地

址二項(xiàng),我們把這些聯(lián)系較為緊密的內(nèi)容又用單獨(dú)的結(jié)構(gòu)表示,這樣就產(chǎn)生了電子

通訊錄的基本結(jié)構(gòu):

struct addr /*通訊地址結(jié)構(gòu)定義*/

{ char post_num[10]; /*郵編*/

char addr[40]; /*家庭地址*/

};

struct birth /*出生年月結(jié)構(gòu)定義*/

{ int year; /*年份*/

int month; /*月份*/

int day; /*日期*/

};

struct friend /*電子通訊錄結(jié)構(gòu)定義*/

{ int number; /*序號*/

char name[20] /*姓名*/

char sex; /*性別*/

struct birth birth; /*出生年月*/

struct addr addr; /*通信地址*/

char telephone[13]; /*聯(lián)系電話*/

};

定義的主結(jié)構(gòu)friend包含了前述的五項(xiàng)內(nèi)容 name,sex,和telephone分別代表

了姓名,性別和聯(lián)系電話。為了讓結(jié)構(gòu)中的各項(xiàng)組分更加清晰,定義了二個

小結(jié)構(gòu)birth 和addr分別代表出生年月和通訊地址,因此實(shí)際上friend包含了

8項(xiàng)內(nèi)容。

有了結(jié)構(gòu)定義后,我們可以很輕松地構(gòu)造出電子通訊錄的主體:

stryct friend friends[50];

采用一維數(shù)組 friends[50],正是用到了順序表這種最簡單的數(shù)據(jù)結(jié)構(gòu)來表示

問題。

2.增添電子通訊錄中的內(nèi)容

對于電子通訊錄這樣一張順序表來說,內(nèi)容的錄入是必不可少的操作。由

于采用的是順序存儲結(jié)構(gòu)。這項(xiàng)工作很簡單,只需要在把輸入的信息按順序放

在空的friends數(shù)組元素中即可。函數(shù)Data_Input完成了信息的錄入工作:

void Data_input(int j)

{

friends[j].number=j;

printf("\n\n\n\tNo %d record",j);

printf("\n\n\tName:"); /*讀入姓名*/

scanf("%s",friends[j].name);

printf("\n\tSex(m/f):"); /*讀入姓別*/

scanf("%c",friends[j].sex);

printf("\n\tbirthday:"); /*讀入出生年月*/

printf("\n\t\tyear:");

scanf("%d",friends[j].birth.year);

printf("\n\t\tmonth");

scanf("%d",friends[j].birth.month);

printf("\n\t\tday");

scanf("%d",friends[j].birth.day);

printf("\n\tPost number:"); /*讀入郵編*/

scanf("%s",friends[j].addr.post_num);

printf("\n\tAddress:"); /*讀入家庭地址*/

scanf("%s",friends[j].addr.addr);

printf("\n\ttelephone:"); /*讀入聯(lián)系電話*/

scanf("%s",friends[j].telephone);

}

C語言程序設(shè)計:通訊錄程序設(shè)計

#include "stdlib.h"

#include "string.h"

#include "conio.h"

#include "stdio.h"

#include "dos.h"

FILE *fp;

int i; //i是全局變量 可代替length

struct address

{ char postnum[10];

char a[40]; //家庭地址

};

struct birthday

{ int year;

int month;

int day;

};

struct ffriend

{ int num; //序號

char name[20];

char sex;

char telephone[13];

struct birthday birthday;

struct address address;

}

friends[50];

void Load()

{

int j;

long k;

fp=fopen("friend.txt","a+"); //打開文件friend.txt

if(fp!=NULL)

{

for(i=1;i50;i++)

{

j=fgetc(fp);

if(j==EOF) //判斷是否到了文件尾

return;

k=i-1;

fseek(fp,k*sizeof(struct ffriend),SEEK_SET);

fread(friends[i],sizeof(struct ffriend),1,fp); //從文件中讀取一條記錄

}

}

else

{

fp=fopen("friend.txt","w");

i=1;

}

}

void Show(int j)

{

// friends[j].num=i;

printf("\n\n\t編號-Nnumber: %3d",friends[j].num);

printf("\n\t姓名-Name:%-20s",friends[j].name);

printf("\n\t性別-Sex:%c",friends[j].sex);

printf("\n\t聯(lián)系電話-Telephone:%-13s",friends[j].telephone);

printf("\n\t出生日期-Birthday:%4d-%2d-%3d",friends[j].birthday.year,friends[j].birthday.month,friends[j].birthday.day);

printf("\n\t郵編-Postnum:%-10s",friends[j].address.postnum);

printf("\n\t通信地址-address:%-40s",friends[j].address.a);

}

void Append(int j)

{

fflush(stdin); //區(qū)內(nèi)清除文件緩沖區(qū),文件以寫方式打開時將緩沖容寫入文件

//stdin是一個標(biāo)準(zhǔn)FILE*(文件型指針)指向通常是用鍵盤的輸入的輸入流

friends[j].num=j;

printf("\n\t\t\t序號-Number:%d",j);

printf("\n\t\t\t姓名-Name:");

scanf("%s",friends[j].name);

fflush(stdin); //為什么沒有fflush(stdin); 的效果會自動跳過呢?

printf("\t\t\t性別-Sex(m/w):"); //為什么輸入漢字男女也會自動跳過聯(lián)系電話呢

scanf("%c",friends[j].sex);

printf("\t\t\t聯(lián)系電話-telephone:");

scanf("%s",friends[j].telephone);

printf("\t出生日期-birthday");

printf("\n\t\t\t年份-year:");

scanf("%d",friends[j].birthday.year);

printf("\t\t\t月份-month:");

scanf("%d",friends[j].birthday.month);

printf("\t\t\t日-day:");

scanf("%d",friends[j].birthday.day);

printf("\t\t\t郵編-Postnumber:");

scanf("%s",friends[j].address.postnum);

printf("\t\t\t通信地址-Address:");

scanf("%s",friends[j].address.a);

getchar();

}

void Delete()

{

int k;

printf("\n\tDelete 序號-Number:");

scanf("%d",k);

if(k=i)

{

for(int j=k;ji+1;j++) /*插入位置后的元素順序后移*/

{

strcpy(friends[j].name,friends[j+1].name); /*交換元素內(nèi)容*/

friends[j].sex=friends[j+1].sex;

strcpy(friends[j].telephone,friends[j+1].telephone);

friends[j].birthday.year=friends[j+1].birthday.year;

friends[j].birthday.month=friends[j+1].birthday.month;

friends[j].birthday.day=friends[j+1].birthday.day;

strcpy(friends[j].address.postnum,friends[j+1].address.postnum);

strcpy(friends[j].address.a,friends[j+1].address.a);

}

i--;

}

else

{

printf("輸入的序號太大!");

}

}

void Modify(int j)

{

Append(j);

}

void Save()

{

int j;

fp=fopen("friend.txt","w");

for(j=1;j=i;j++)

{

fwrite(friends[j],sizeof(struct ffriend),1,fp);

}

fclose(fp);

}

void main()

{

int j;

char grade;

char searchname[10];

Load();

i--;

do

{

printf("\t\t\t\t簡易通訊錄\n\n");

printf("功能選擇(Function choose)\n");

printf("\1A.讀取(Read)\n");

printf("\2B.增添(Append)\n");

printf("\6C.插入(Insert)\n");

printf("\5D.刪除(Delete)\n");

printf("\5E.查詢(Search)\n");

printf("\6F.修改(Modify)\n");

printf("\2G.保存(Save)\n");

printf("\1H.退出(Quit)\n");

printf("請選擇(Choice)\n注:輸入A~H的大寫字母\n");

scanf("%c",grade);

switch(grade)

//加個大寫和小寫 都可以啊

{

case 'A': j=1; //顯示功能

while(getchar()!=0x1bj=i) //增添按Esc鍵退出

{

Show(j++);

printf("\n請按回車鍵繼續(xù)!");

}

if(j-11)

{

printf("\n\t空文檔,無任何記錄-Empty Note\n");

printf("\n請按回車鍵繼續(xù)!");

getchar();

}

printf("\n\t\t\t\t\t\t\t此次操作結(jié)束");

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

break;

case 'B': //增加功能

while(i=50) //增加按ESC鍵退出的功能

{

i++;

Append(i);

printf("\t是否繼續(xù)增加?y/n");

//修改 加上else if 其他就跳出或強(qiáng)制打印出出錯

char a=getchar();

if(a=='n'||a=='N')

break;

}

if(i==51)

printf("\n\t文檔已滿,無法增加記錄-note full");

printf("\n\t\t\t\t\t\t\t此次操作結(jié)束");

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

getchar();

break;

case 'C':

int k;

printf("\n\t輸入要插入的位置:");

scanf("%d",k);

j=i+1;

friends[j].num=j;

for(j;jk;j--) //插入功能

{

strcpy(friends[j].name,friends[j-1].name); //數(shù)據(jù)后移

friends[j].sex=friends[j-1].sex;

strcpy(friends[j].telephone,friends[j-1].telephone);

friends[j].birthday.year=friends[j-1].birthday.year;

friends[j].birthday.month=friends[j-1].birthday.month;

friends[j].birthday.day=friends[j-1].birthday.day;

strcpy(friends[j].address.postnum,friends[j-1].address.postnum);

strcpy(friends[j].address.a,friends[j-1].address.a);

}

Append(k);

i++;

printf("\n\t\t\t\t\t\t\t此次操作結(jié)束");

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

break;

case 'D': //刪除功能 //增添隨意刪除多條記錄的功能

Delete();

if(i1)

printf("\n沒有記錄-No records\n");

printf("\n請按回車鍵繼續(xù)!");

getchar();

getchar();

printf("\n\t\t\t\t\t\t\t此次操作結(jié)束");

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

break;

case 'E': //查詢功能

printf("\n\t請輸入要查詢記錄的相關(guān)姓名:"); //增添查詢按列號的

scanf("%s",searchname);

for(j=1;j=i;j++)

{

if(strcmp(searchname,friends[j].name)==0) //比較字符串

{

Show(j);

break;

}

}

if(i1)

{

printf("\n 沒有您所查詢的記錄-No records");

printf("\n 請按回車鍵繼續(xù)!");

getchar();

}

printf("\n\t\t\t\t\t\t\t此次操作結(jié)束");

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

getchar();

break;

case 'F': //修改功能 / /增添按序列號查詢

printf("\n\t請輸入要修改記錄的相關(guān)姓名:");

gets(searchname);

scanf("%s",searchname);

for(j=1;j=i;j++)

{

if(strcmp(searchname,friends[j].name)==0) //比較字符串

{

Modify(j);

// getchar(); //加個輸出確定修改嗎

}

}

if(i1) //修改功能

{ printf("\n 沒有您所要修改的記錄-No records");

printf("\n 請按回車鍵繼續(xù)!");

getchar();

getchar();

}

printf("\n\t\t\t\t\t\t\t此次操作結(jié)束");

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

break;

case 'G':

Save(); //存盤功能

getchar();

printf("\n\t\t\t\t\t\t\t此次操作結(jié)束");

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

break;

case 'H': //退出功能

char x;

printf("是否保存?yes/no\n");

scanf("%s",x);

//getchar();

// getchar();

if(x=='y')

{

Save();

exit(0);

}

else

exit(0);

default:

printf("\n\t輸入有誤,請輸入正確的序列號!");

printf("\n請按回車鍵繼續(xù)!");

getchar();

printf("\n\t\t\t\t\t\t\t此次操作結(jié)束");

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

}

}while(1);

}


文章題目:c語言通訊錄的函數(shù)流程 用c語言編寫簡單的通訊錄
地址分享:http://fisionsoft.com.cn/article/ddjgsos.html