c語言號碼
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]='