You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <stdio.h>
# include <process.h>
# include <stdlib.h>
# include <string.h>
//定义函数
FILE * fp ; //文件指针
void menu ( ) ;
void add ( ) ;
void search ( ) ;
void modify ( ) ;
void look ( ) ;
void quit ( ) ;
//主函数
int main ( )
{
menu ( ) ;
return 0 ;
}
//通讯录结构体
struct user
{
char name [ 8 ] ; //姓名
char place [ 15 ] ; //籍贯
char tel1 [ 15 ] ; //电话1
char tel2 [ 15 ] ; //电话2
char email [ 20 ] ; //电子邮箱
} user [ 50 ] ;
//菜单
void menu ( )
{
system ( " cls " ) ;
system ( " color f3 " ) ;
int n ;
printf ( " \n \n \n \n \n " ) ;
printf ( " \t \t :---------通讯录---------: \n " ) ;
printf ( " \t \t : 1:新建 : \n " ) ;
printf ( " \t \t : 2:查询 : \n " ) ;
printf ( " \t \t : 3:修改 : \n " ) ;
printf ( " \t \t : 4:浏览 : \n " ) ;
printf ( " \t \t : 5:退出 : \n " ) ;
printf ( " \t \t :--输入数 <1-5>选择功能--: \n \n " ) ;
scanf ( " %d " , & n ) ;
switch ( n )
{
case 1 : add ( ) ; break ; //添加
case 2 : search ( ) ; break ; //查询
case 3 : modify ( ) ; break ; //修改
case 4 : look ( ) ; break ; //浏览
case 5 : return ; break ; //退出
default : return ;
}
}
//添加用户信息
void add ( )
{
struct user one ;
system ( " color e3 " ) ;
if ( ( fp = fopen ( " user.txt " , " ab " ) ) = = NULL )
{
printf ( " 打开文件失败! \n " ) ;
exit ( 0 ) ;
}
printf ( " \n 请输入用户姓名: " ) ;
scanf ( " %s " , one . name ) ;
printf ( " \n 请输入用户籍贯: " ) ;
scanf ( " %s " , one . place ) ;
printf ( " \n 请输入用户电话号码1: " ) ;
scanf ( " %s " , one . tel1 ) ;
printf ( " \n 请输入用户电话号码2: " ) ;
scanf ( " %s " , one . tel2 ) ;
printf ( " \n 请输入用户电子邮箱: " ) ;
scanf ( " %s " , one . email ) ;
fwrite ( & one , sizeof ( struct user ) , 1 , fp ) ; //把数据块录入user.txt中
fclose ( fp ) ;
printf ( " \n 注册成功! \n " ) ;
system ( " pause " ) ;
menu ( ) ;
} ;
//修改
void modify ( )
{
menu ( ) ;
}
//查询
void search ( )
{
menu ( ) ;
}
//浏览
void look ( )
{
menu ( ) ;
return ;
}
//退出
void quit ( )
{
return ;
}