当前位置:首页 » 编程语言 » c语言11位手机号
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

c语言11位手机号

发布时间: 2023-05-28 04:28:59

c语言 随机产生10个手机号,不能重复。输入英文名后绑定手机号,一个名字一个手机号

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

constintPHONE_LENGTH=11;

constchar*PREFIX="139";

typedefstruct{

intavailable;
charnumber[PHONE_LENGTH+1];
charowner_name[31];
}PhoneNumber;


voidphoneNumberGenerator(PhoneNumber*phones,intsize,constchar*prefix);
voiddisplayPhoneNumber(PhoneNumber*phones,intsize);
intmain(void)
{


chartname[31];
intid;
PhoneNumberphones[10];

phoneNumberGenerator(phones,10,PREFIX);

displayPhoneNumber(phones,10);
while(1)
{
puts("请输入您的姓名");
scanf("%s",tname);

puts("请输入您喜欢号码的编号");
scanf("%d",&id);

if(phones[id].available)
{
strcpy(phones[id].owner_name,tname);

phones[id].available=0;

displayPhoneNumber(phones,10);
}else
{
puts("此号已被占用,请选择其他的号码");

}}return0;
}


voidphoneNumberGenerator(PhoneNumber*phones,intsize,constchar*prefix)
{

intrepeat;//重复标志变量

for(inti=0;i<size;++i)
{

strncpy(phones[i].number,prefix,strlen(prefix));//复制号码前缀
phones[i].available=1;//初始化号码为可用
strcpy(phones[i].owner_name,"unknow");//初始化号码的拥有着为"unknow"//开始产生号码
do{

repeat=0;
/*******************产生一个随机号码******************/
for(intj=strlen(prefix);j<PHONE_LENGTH;++j)
{
(phones[i].number)[j]=rand()%10+'0';

}
(phones[i].number)[PHONE_LENGTH]='';

/************************检测重复性**************************/
for(intk=0;k<i;k++)
{
if(strcmp(phones[i].number,phones[k].number)==0)
{
repeat=1;
break;

}

}
}while(repeat);//如果当前产生的号码与之前的重复了,则再生成一个,直到不重复为止

}}


voiddisplayPhoneNumber(PhoneNumber*phones,intsize)
{


printf("%-5s%-20s%-10s%s ","编号","号码","状态","拥有者");
for(inti=0;i<size;++i)
{


printf("%-5d%-20s%-10s%s ",i,phones[i].number,phones[i].available?"可用":"已占用",phones[i].owner_name);


}

}

② c语言编程题要求用函数和指针求判断一个字符串是否为手机号,不 (手机要是11为什么全为阿拉伯字母)

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

int istelnum(char *num)
{
int i;

for(i=0;num[i];i++)
{
if(!(num[i]>='0'&&num[i]<='9'))
return 0;
}
return 11==strlen(num);
}

int main()
{
char num[16];

printf("请输入手机号:");
gets(num);
if(istelnum(num))
puts("是有效的手机号\n");
else
puts("不是有效的手机号\n");
return 0;
}

③ 用c语言编写通讯录

自己写的,看一下

// 头文件部分

//============================
#include <stdio.h>
#include <windows.h>
#include <stdlib.h>

#include <conio.h>

// 初始化数据部分
int Menu();
void Start();
void Write();
void Read();
void Search();
void Detele();
void beauty();
void Rework();
void Lock();
int Judge();
//============================
struct Student{
char name[20];
char Tel[20];
char QQ[20];
int age;
}xy[100];
char wenjian[10000];
char Number[10];
char number=0;
int GOTO;
//
int main()
{
Start();
for(;;)
{
GOTO=Menu();
if(GOTO==1)
{
for(;;)
{
Write();
int judge=Judge();
if(judge==2)
{
break;
}
}
}
if(GOTO==2)
{
for(;;)
{
Read();
system("pause");
break;
}
}
if(GOTO==3)
{
for(;;)
{
Search();
int judge=Judge();
if(judge==2)
{
break;
}
}
}
if(GOTO==4)
{
for(;;)
{
Rework();
int judge=Judge();
if(judge==2)
{
break;
}
}
}
if(GOTO==5)
{
Detele();
break;
}
if(GOTO==6)
{
beauty();
break;
}
if(GOTO==7)
{
}
if(GOTO==8)
{
printf("");
break;
}
if(GOTO==9)
{
printf("\t\t\t退出系统\n\n");
return 0;
}
if(GOTO==0)
{
printf("");
break;
}
}
// beauty();
//
// Write();
// Read();
// Search();
// Rework();
// Detele();
return 0;
}

void Write()
{
printf("\t\t\t请输入好友名字\n");
scanf("%s",&xy[number].name);
printf("\t\t\t请输入好友电话号码\n");
scanf("%s",&xy[number].Tel);
printf("\t\t\t请输入好友QQ号码\n");
scanf("%s",&xy[number].QQ);
printf("\t\t\t请输入好友年龄\n");
scanf("%d",&xy[number].age);

FILE *file;
if((file=fopen("Friend.txt","rt"))==NULL)
{
file=fopen("Friend.txt","wt");
fprintf(file,"%-20s%-20s%-20s%-20s","姓名","电话","QQ","年龄");
}
file=fopen("Friend.txt","at");
fprintf(file,"%-20s%-20s%-20s%-20d\n",xy[number].name,xy[number].Tel,xy[number].QQ,xy[number].age);
fclose(file);
number++;
Number[0]=number;
FILE * Sta;
if((Sta=fopen("number.txt","r"))=NULL)
{
Sta=fopen("number.txt","wt");
exit(1);
}
Sta=fopen("number.txt","wt");
fprintf(Sta,"%d",Number[0]);

fclose(Sta);
}

void Read()
{
printf("\t\t\t您通讯录中一共有%d位好友\n",Number[0]);

FILE* read;
if((read=fopen("Friend.txt","r"))=NULL)
{
printf("\t\t\t您通讯中当前没有好友,请返回添加\n");
}
read=fopen("Friend.txt","rt");
printf("%-20s%-20s%-20s%-20s\n","姓名","电话 ","QQ","年龄");
for(int i=0;i<number;i++)
{

fscanf(read,"%s%s%s%d\n",&xy[i].name,&xy[i].Tel,&xy[i].QQ,&xy[i].age);

printf("%-20s%-20s%-20s%-20d\n",xy[i].name,xy[i].Tel,xy[i].QQ,xy[i].age);

}
/* fread(wenjian,10000,1,read);
for(int i=0;i<number*80+80;i++)
{
printf("%c",wenjian[i]);

}
printf("\n");
*/

fclose(read);
}

void beauty()
{

int d;
do{
printf("choose");
scanf("%d",&d);
}while(d<1&&d>5);
if(d==1)
{
system("color 27");
printf("===1===");

}
if(d==2)
{
system("color 37");
printf("===2===");
}
if(d==3)
{
system("color 47");
printf("===3===");
}
if(d==4)
{
system("color 57");
printf("===4===");
}
if(d==5)
{
system("color 67");
printf("===5===");
}

}
void Start()
{
FILE* Start;
if((Start=fopen("number.txt","r"))==NULL)
{
Start=fopen("number.txt","w");
number=0;
Number[0]=number;
fscanf(Start,"%d",&Number[0]);
printf("\t\t\t您的通讯录中还没有任何好友,赶快添加吧.此次操作需要重新运行程序。\n");
exit(1);
}
Start=fopen("number.txt","r");
fscanf(Start,"%d",&Number[0]);

number=Number[0];

fclose(Start);

}

void Search()
{
int change=0;
char Searchname[20];
printf("\t\t\t输入要查找的好友的名字\n\n");
scanf("%s",&Searchname);
fflush(stdin);
printf("\t\t\t您要查找的好友是 %s \n\n",Searchname);

FILE *Search;
Search=fopen("Friend.txt","rt");

for(int i=0;i<=number;i++)
{

fscanf(Search,"%s%s%s%d\n",&xy[i].name,&xy[i].Tel,&xy[i].QQ,&xy[i].age);

if(strcmp(xy[i].name,Searchname)==0)
{
printf("\t\t\t下面是该好友的信息:\n\n");
printf("%-20s%-20s%-20s%-20s\n","姓名","电话 ","QQ","年龄");
printf("%-20s%-20s%-20s%-20d\n",&xy[i].name,&xy[i].Tel,&xy[i].QQ,xy[i].age);
change=1;
}

fclose(Search);
}
if(change==0)
{
printf("\t\t\t您要查找的好友不存在,请返回菜单添加。\n");
}
}

void Rework()
{
char Rework[20];
printf("\t\t\t输入要修改的好友的名字\n\n");
scanf("%s",&Rework);

printf("\t\t\t您要修改 %s 的信息\n\n",Rework);
int Change=0;
FILE *Search;
Search=fopen("Friend.txt","rt");

for(int i=0;i<=number;i++)
{

fscanf(Search,"%s%s%s%d\n",&xy[i].name,&xy[i].Tel,&xy[i].QQ,&xy[i].age);

if(strcmp(xy[i].name,Rework)==0)
{
printf("\t\t\t下面是该好友的信息:\n\n");
printf("%-20s%-20s%-20s%-20s\n","姓名","电话 ","QQ","年龄");
Change=1;
int Choose;
printf("%-20s%-20s%-20s%-20d\n",&xy[i].name,&xy[i].Tel,&xy[i].QQ,xy[i].age);
//---------------------------------------------------------------------
do
{
printf("\t\t\tchoose\t\t\t1-----3");

scanf("%d",&Choose);
}while(Choose>3||Choose<1);
if(Choose==1){

printf("\t\t\t请输入好友电话号码\n");
scanf("%s",&xy[i].Tel);
}
if(Choose==2)
{
printf("\t\t\t请输入好友QQ号码\n");
scanf("%s",&xy[i].QQ);
}
if(Choose==3)
{
printf("\t\t\t请输入好友年龄\n");
scanf("%d",&xy[i].age);
}

Search=fopen("Friend.txt","wt");
for(int sta=0;sta<i;sta++)
{
fprintf(Search,"%-20s%-20s%-20s%-20d\n",xy[sta].name,xy[sta].Tel,xy[sta].QQ,xy[sta].age);
}
if(sta==i)
{
fprintf(Search,"%-20s%-20s%-20s%-20d\n",xy[i].name,xy[i].Tel,xy[i].QQ,xy[i].age);
i++;
}
for(i;i<=number;i++)
{
fprintf(Search,"%-20s%-20s%-20s%-20d\n",xy[i].name,xy[i].Tel,xy[i].QQ,xy[i].age);
}
printf("\t\t\t修改后的信息为:\n\n");
Read();

}

fclose(Search);
}
if(Change==0)
{
printf("\t\t\t您要查找的好友不存在,请返回菜单添加。\n");
}
}
void Detele()
{

int change=0;
char delete_friend[20];
printf("\t\t\t输入要删除的好友的名字\n\n");
scanf("%s",&delete_friend);
fflush(stdin);
printf("\t\t\t您要删除的好友是 %s \n\n",delete_friend);

FILE *DeleteF;
DeleteF=fopen("Friend.txt","rt");

for(int i=0;i<=number;i++)
{

fscanf(DeleteF,"%s%s%s%d\n",&xy[i].name,&xy[i].Tel,&xy[i].QQ,&xy[i].age);

if(strcmp(xy[i].name,delete_friend)==0)
{
printf("\t\t\t下面是该好友的信息:\n\n");
printf("%-20s%-20s%-20s%-20s\n","姓名","电话 ","QQ","年龄");
printf("%-20s%-20s%-20s%-20d\n",&xy[i].name,&xy[i].Tel,&xy[i].QQ,xy[i].age);
change=1;

DeleteF=fopen("Friend.txt","wt");
for(int st=0;st<i;st++)
{
fprintf(DeleteF,"%-20s%-20s%-20s%-20d\n",xy[st].name,xy[st].Tel,xy[st].QQ,xy[st].age);

}
i++;
for(i;i<=number;i++)
{
printf("%-20s%-20s%-20s%-20d\n",xy[i].name,xy[i].Tel,xy[i].QQ,xy[i].age);
fprintf(DeleteF,"%-20s%-20s%-20s%-20d\n",xy[i].name,xy[i].Tel,xy[i].QQ,xy[i].age);
}
}
//--------------------------------------------------------------------------------

if(change==1)
{
printf("\t\t\t删除后的通讯录信息为:\n\n");

number--;
Number[0]=number;
FILE * St;
if((St=fopen("number.txt","r"))=NULL)
{
St=fopen("number.txt","wt");
exit(1);
}
St=fopen("number.txt","wt");
fprintf(St,"%d",Number[0]);

fclose(St);

fclose(DeleteF);
Start();
Read();
}
}

if(change==0)
{
printf("\t\t\t您要删除的好友不存在。\n");
}

}

void Lock()
{

}

int Menu()
{
printf("\t\t*****欢迎进入通讯管理界面*****\n\n");

printf("\t\t\t1.添加我的好友\n");
printf("\t\t\t2.显示所有好友\n");
printf("\t\t\t3.查找我的好友\n");
printf("\t\t\t4.修改好友信息\n");
printf("\t\t\t5.删除我的好友\n");
printf("\t\t\t6.设置背景颜色\n");
printf("\t\t\t7.设置管理密码\n");
printf("\t\t\t8.使用注意事项\n");
printf("\t\t\t9.退出通讯系统\n");
printf("\t\t\t0.作者想说的话\n");
printf("\t\t******************************\n\n");

do{
printf("\t\t\t请输入你的选择:\n\n");
scanf("%d",&GOTO);
}while(GOTO>9||GOTO<1);
return GOTO;
}

int Judge()
{
char JUDGE;
do
{
printf("\t\t\t是否继续当前操作\n\n Y(yes) / N(no)\n");
printf("\t\t\t输入你的选择\n");
JUDGE=getch();
if(JUDGE=='y'||JUDGE=='Y')
{
return 1;
}
if(JUDGE=='n'||JUDGE=='N')
{
return 2;
}
}while(JUDGE!='y'||JUDGE!='n');

}

④ 跪求c语言计数代码

计数很简单啊!可以用一个共用变量来计数,最好的是用多线程的方法,因为如果你文件太大了,程序在加载过程中就会卡主,多线程可以实时的显示字符数

⑤ c语言关于手机号码的问题 检查我的代码的问题

把整数字符和整数搞混了,比如你的if(st[0]!=1)就应该写成if(st[0]!='1'),记得加上单引号.

采纳哦