1. c语言制作简单的通讯录

/*编程建立一通讯簿,存放有姓名、电话号码、住址,然后对通信簿进行查找、添加、修改及删除。*/
#include<stdio.h>
struct person
{
char name[8];
char tel[15];
char addr[50];
};

char filename[20];
FILE *fp;

void creat();
void output();
void search();
void append();
void modify();
void delete();

main()
{
int m;

creat();
while(1)
{
printf("\n\n添加,请按1");
printf("\n查找,请按2");
printf("\n修改,请按3");
printf("\n删除,请按4");
printf("\n输出,请按5");
printf("\n退出,请按0\n");
scanf("%d",&m);
if(m>=0&&m<=5)
{
switch(m)
{
case 1: append();
break;
case 2: search();
break;
case 3: modify();
break;
case 4: delete();
break;
case 5: output();
break;
case 0: exit();
}
printf("\n\n操作完毕,请再次选择!");
}
else
printf("\n\n选择错误,请再次选择!");
}
}

void creat()
{
struct person one;
long s1;

printf("\n请输入通讯簿名:");
scanf("%s",filename);
if((fp=fopen(filename,"w"))==NULL)
{
printf("\n不能建立通讯簿!");
exit();
}
fprintf(fp,"%-10s%-20s%-50s\n","姓名","电话号码","住址");
printf("\n请输入姓名、电话号码及住址(以0结束)\n");
scanf("%s",one.name);
while(strcmp(one.name,"0"))
{
scanf("%s%s",one.tel,one.addr);
fprintf(fp,"%-10s%-20s%-50s\n",one.name,one.tel,one.addr);
scanf("%s",one.name);
}
fclose(fp);
}

void output()
{
struct person one;

if((fp=fopen(filename,"r"))==NULL)
{
printf("\n不能打开通讯簿!");
exit();
}
printf("\n\n%20s\n","通 讯 簿");
while(!feof(fp))
{
fscanf(fp,"%s%s%s\n",one.name,one.tel,one.addr);
printf("%-10s%-20s%-50s",one.name,one.tel,one.addr);
}
fclose(fp);
}

void append()
{
struct person one;

if((fp=fopen(filename,"a"))==NULL)
{
printf("\n不能打开通讯簿!");
exit();
}
printf("\n请输入添加的姓名、电话号码及住址\n");
scanf("%s%s%s",one.name,one.tel,one.addr);
fprintf(fp,"%-10s%-20s%-50s\n",one.name,one.tel,one.addr);
fclose(fp);
}

void search()
{
int k=0;
char namekey[8];
struct person one;

printf("\n请输入姓名:");
scanf("%s",namekey);

if((fp=fopen(filename,"rb"))==NULL)
{
printf("\n不能打开通讯簿!");
exit();
}
while(!feof(fp))
{
fscanf(fp,"%s%s%s\n",one.name,one.tel,one.addr);
if(!strcmp(namekey,one.name))
{
printf("\n\n已查到,记录为:");
printf("\n%-10s%-18s%-50s",one.name,one.tel,one.addr);
k=1;
}
}
if(!k)
printf("\n\n对不起,通讯簿中没有此人的记录。");
fclose(fp);
}

void modify()
{
int m,k=0;
long offset;
char namekey[8];
struct person one;

printf("\n请输入姓名:");
scanf("%s",namekey);

if((fp=fopen(filename,"r+"))==NULL)
{
printf("\n不能打开通讯簿!");
exit();
}
while(!feof(fp))
{
offset=ftell(fp);
fscanf(fp,"%s%s%s\n",one.name,one.tel,one.addr);
if(!strcmp(namekey,one.name))
{
k=1;
break;
}
}
if(k)
{
printf("\n已查到,记录为:");
printf("\n%-10s%-18s%-50s",one.name,one.tel,one.addr);
printf("\n请输入新姓名、电话号码及住址:");
scanf("%s%s%s",one.name,one.tel,one.addr);
fseek(fp,offset,SEEK_SET);
printf("%ld",ftell(fp));
fprintf(fp,"%-10s%-20s%-50s\n",one.name,one.tel,one.addr);
}
else
printf("\n对不起,通讯簿中没有此人的记录。");
fclose(fp);
}

void delete()
{
int m,k=0,flag;
long offset1,offset2;
char namekey[8], valid[4];
struct person one;

printf("\n请输入姓名:");
scanf("%s",namekey);
if((fp=fopen(filename,"r+"))==NULL)
{
printf("\n不能打开通讯簿!");
exit();
}
while(!feof(fp))
{
offset1=ftell(fp);
fscanf(fp,"%s%s%s\n",one.name,one.tel,one.addr);
if(!strcmp(namekey,one.name))
{
k=1;
break;
}
}
if(k)
{
printf("\n已查到,记录为");
printf("\n%-10s%-18s%-50s",one.name,one.tel,one.addr);
printf("\n确实要删除,按1;不删除,按0:");
scanf("%d",&m);
if(m)
{
fseek(fp,offset1,SEEK_SET);
fprintf(fp,"%-10s%-20s%-50s\n","","","");
}
}
else
printf("\n对不起,通讯簿中没有此人的记录。");
fclose(fp);
}

2. 怎么给C语言中的字符串编号。

抽象一点,比如一个字符串100字符,内存地址+(编号*100)就是字符串地址了。

3. c语言中的|号表示什么意思

a|b 就是把整数a b都转换成2进制,然后右对齐写出来,两个都是0就是0,否则是1。

4. c语言通讯录代码

#include
#include
#include
#include
#define maxlen 15
struct persons
{
int num;
char name[20];
char e_addr[20];
char tel_no[15];
char sim_no;
char arch;
}persons[maxlen];

typedef struct lnode{
int num;
char name[20];
char e_addr[20];
char tel_no[15];
char sim_no;
char arch;
struct lnode *next;
}listnode,*linklist;

linklist head=NULL,r=NULL;
listnode *s,*p0,*p1,*p2,*p3,*p4,*p5,*p6,*p7,*p8,*p9;
int i;
char name1[10],ch;char tel_no1[15];char arch1;char sim_no1;char e_addr1[20];
char s1[20];
FILE *fp;

void creat()
{
int j;
long k;
fp=fopen("数据文件.txt","r t");
if(fp!=NULL)
{for(i=0;i<=maxlen;i++ )
{ j=fgetc(fp);
if(j==EOF)
return;
k=i;
fseek(fp,k*sizeof(struct persons),0);
fread(&persons[i],sizeof(struct persons),1,fp);

s=(linklist)malloc(sizeof(listnode));
s->num=persons[i].num;
strcpy(s->name,persons[i].name);
strcpy(s->e_addr,persons[i].e_addr);
strcpy(s->tel_no,persons[i].tel_no);
s->sim_no=persons[i].sim_no;
s->arch=persons[i].arch;
if(head==NULL)
{head=s;r=head;head->next=NULL;}
else
{r->next=s;
r=s;r->next=NULL;
}}fclose(fp);}
else
{ fp=fopen("数据文件.txt","w");
i=1;
}
}
void ShowA()
{p1=head;

while(p1!=NULL)
{if(p1->arch=='A')
{
cout<<endl;
cout<name<<endl;
cout<tel_no<<endl;
cout<sim_no<<endl;}
p1=p1->next;continue;}
}
void ShowB()
{p1=head;

while(p1!=NULL)
{if(p1->arch=='B')
{
cout<<endl;
cout<name<<endl;
cout<tel_no<<endl;
cout<sim_no<<endl;}
p1=p1->next;continue;}
}
void ShowC()
{p1=head;

while(p1!=NULL)
{if(p1->arch=='C')
{
cout<<endl;
cout<name<<endl;
cout<tel_no<<endl;
cout<sim_no<<endl;}
p1=p1->next;continue;}
}
void Show()
{char ch1;
printf(" Which arch do you want to show?\n");
cout<<" A:同学同事"<<"B:家人"<<"C:其他"<<endl;
cout<<"请选择:"<<endl;
cin>>ch1;
switch(ch1)
{case'A':ShowA();break;
case'B':ShowB();break;
case'C':ShowC();break;
default:cout<<"error"<<endl;
}
}

void Delete()
{ printf("\n\n\t 请输入要删除用户的姓名:");

cin>>name1;
p4=head;
if(strcmp(p4->name,name1)==0)
{ p4=p4->next;
head=p4;
}
else
{ while(strcmp(p4->next->name,name1)!=0)
p4=p4->next;
p5=p4->next;
p4->next=p5->next;
free(p5);
}
}
void Input()
{ s=(linklist)malloc(sizeof(listnode));

printf("\n\n\t 请输入该用户的信息:");

cout<<"name:";
cin>>s->name;
cout<<"tel_no:";
cin>>s->tel_no;
cout<<"sim_no:";
cin>>s->sim_no;
cout<<"e_addr:";
cin>>s->e_addr;
cout<<"arch:";
cin>>s->arch;

if(head==NULL)printf("\n\n");
else
{p8=head;
while(p8!=NULL&&strcmp(s->name,p8->name)!=0&&strcmp(s->tel_no,p8->tel_no)!=0)
p8=p8->next;
if(p8!=NULL)
{printf(" 您添加的用户已存在!");
free(s);}}

if(head==NULL)
{head=s;head->next=NULL;}
else
{r->next=s;
r=s;r->next=NULL;}
}

void Alter()
{

printf("\n\n\t 请输入姓名:");

cin>>name1;
p3=head;
while(p3!=NULL&&strcmp(name1,p3->name)!=0)
p3=p3->next;
if(p3==NULL)
printf("\n\n\t 您选择的用户不存在!");
else
{ printf("\n\n\t 请输入该用户的新信息!");

cout<<"name:";
cin>>name1;
cout<<"tel_no:";
cin>>tel_no1;
cout<<"e_addr:";
cin>>e_addr1;
cout<<"sim_no:";
cin>>sim_no1;
cout<<"arch:";
cin>>arch1;
while(p9!=NULL&&strcmp(name1,p9->name)!=0&&strcmp(tel_no1,p9->tel_no)!=0)
p9=p9->next;
if(p9==NULL)
{strcpy(p3->name,name1);
strcpy(p3->tel_no,tel_no1);
strcpy(p3->e_addr,e_addr1);
p3->sim_no=sim_no1;
p3->arch=arch1;
}
else
printf(" 您添加的用户已存在!");

}
}
void Dial()
{int a;char b;
cout<<"1.拨叫用户:"<<endl;
cout<<"2.使用单键拨号:"<<endl;
cin>>a;
p0=head;
if(a==1)
{cout<<" 请输入拨叫用户的姓名:";
cin>>name1;
while(strcmp(name1,p0->name)!=0&&p0!=NULL)
p0=p0->next;
if(p0==NULL)
cout<<" 您选择的用户不存在!";
else
/*for(c=0;c<15;c++)
{cout<<endl;
cout<<(*p0).tel_no[c];}*/
{cout<<endl;
cout<tel_no;
cout<<endl;}
}
else
{cout<<"请输入单键号码:";
cin>>b;
while(p0!=NULL&&b!=p0->sim_no)
p0=p0->next;
if(p0==NULL)
cout<<" 您输入的单键号码不存在!";
else
{cout<<endl;
cout<name<<endl;
cout<tel_no;
cout<<endl;}
}
}

void Save()
{ int j;
fp=fopen("数据文件.txt","w");
for(p2=head,j=0;p2!=NULL;j++ ,p2=p2->next)
{
strcpy(persons[j].name,p2->name);
strcpy(persons[j].tel_no,p2->tel_no);
persons[j].sim_no=p2->sim_no;
strcpy(persons[j].e_addr,p2->e_addr);
persons[j].arch=p2->arch;
fwrite(&persons[j],sizeof(struct persons),1,fp);
}
}

void main()
{ creat();
do
{
printf(" **********************************************************");
printf("\n\n\n\n\t 欢迎来到通讯录!");
printf("\n\n\t\t 请选择操作:");
printf("\n\t\t1. 显示通讯录");
printf("\n\t\t2. 删除通讯录");

printf("\n\t\t3. 添加通讯录");
printf("\n\t\t4. 编辑通讯录");
printf("\n\t\t5. 拨号功能");
printf("\n\t\t6. 保存刚才的操作并退出\n");
printf(" **********************************************************");
printf("\n\n\n");
printf("\t 选择您想要的操作:");
cin>>ch;
switch(ch)
{ case '1': Show();
break;
case '2': Delete();
break;
case '3': Input();
break;
case '4': Alter();
break;
case '5': Dial();
break;
case '6': Save();
fclose(fp);
exit(0);
break;
default:
printf("\n\t*********************************\n");
printf("\n\t The num should 1-6!!! \n");
printf("\n\t**********************************");
break;
}
}while(1);
}

转的.......woyuyuchao

5. C语言编写一个简短的通讯录,输入联系人得知电话号码和性别等基本信息就可以,谢谢!

我重写一个哦

classtongxunlu{
stringa;
stringb;
stringc;
}
tongxunlumyfriend[2];
cin>>myfriend[0].a>>myfriend[0].b>>myfriend[0].c;//给我的朋友赋值,就是添加信息
cout<<myfriend[0].a<<myfriend[0].b<<myfriend[0].c;//输出

这就是给他注入信息然后在取出来个过程,注释写得很详细,根据你的需要自己修改吧,这个是我以前回答别人的时候写的

6. c语言对号码的添加和删除

保存一堆的号码?
可以用链表。 去看看stl中的list

7. C语言,翻译电话号码

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>

charwords[11][8]={"zero","one","two","three","four","five","six","seven","eight","nine","double"};
intwordslen[11];
intstate;//1double过的0没有过的
chartext1[1000];
chartext[1000];
charresult[100];
voidsetlen()
{
intn;
for(n=0;n<11;n++)
{
wordslen[n]=strlen(words[n]);
}
}
voidzhengli()
{
intl,n;
charc;
intnt=0;
l=strlen(text1);
for(n=0;n<l;n++)
{
c=text1[n];
if(c>='a'&&c<='z')
{
text[nt++]=c;
}
elseif(c>='A'&&c<='Z')
{
c+=('a'-'A');
text[nt++]=c;
}
text[nt]='';
}
}
voidzhuanhua()
{
intl,n,r;
intnr=0;
intnnow=0;//目前到了哪个位。
chartt[8];

l=strlen(text);
while(nnow<l)
{
r=-1;
strncpy(tt,&text[nnow],7);
//printf("提取的段式%s ",tt);
for(n=0;n<11;n++)
{
//printf("跟%s比较 ",words[n]);
if(strncmp(tt,(char*)words[n],wordslen[n])==0)
{
r=n;
nnow+=wordslen[n];
break;
}
}
if(r==-1)
{
printf("ERROR. ");
nnow++;
}
if(n>9)
{
state=1;
}
else
{
if(state==1)
{
result[nr++]='0'+r;
state=0;
}
result[nr++]='0'+r;
}
}
result[nr++]='';
printf("结果%s",result);
}
intmain()
{
setlen();
printf("输入要转换的字符串,敲键盘或右键粘贴:");
scanf("%s",text1);
zhengli();//小写化,去空格,去连接符
zhuanhua();
getch();
return0;
}

8. 关于c语言判断电话号码合法问题

#include <stdio.h>
main(){
char phone[15];
int i,flag=0;
int n_digi=0, right_n_digi=9;
printf("please input telephone number\n");
gets(phone);
// 判断 是否是 数字 和 减号:
for (i=0;i<strlen(phone);i++){
if (phone[i] != '-' && ( phone[i]>'9' || phone[i] < '0')) flag = 1;
}
if (flag==1) printf("wrong number\n"); else printf("may right number\n");

// 根据需要,还可以加别的条件判断:
// 例如 总长度判断,例如 必须有 9 个数字:
if (flag==0)
{
for (i=0;i<strlen(phone);i++) { if (phone[i]<='9' && phone[i] >= '0') n_digi++;};
if (n_digi != right_n_digi) printf("wrong number\n"); else printf("may right number\n");
}
return 0;
}

9. 怎么用C语言实现电话号码的匹配。

可以看下正则表达式。