大神求助,c源程序在VS2013上编译时各种语法错误,该如何修改,弄了一早上,还是没搞定
主函数部分:#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct person {
char name[10]; /*姓名*/
char mobile_phone[16]; /*手机号码*/
char fixed_telephone[16]; /*固定电话*/
char work_place[20]; /*工作单位*/
char addr[20]; /*家庭住址*/
char e_mail[30]; /*邮箱*/
char QQ[12]; /*QQ聊天软件*/
char category[10]; /*分类*/
};
char dir_name[20] = "e:\\通讯录.txt";
FILE *fp;
void creat(); /*创建一个通讯录并命名,下次如果要打开以前的通讯录话,就在创建的时候输入以前的文件名称。*/
void output();/*输出模块*/
void add();/*添加模块*/
void modify();/*修改模块*/
void del();/*删除模块*/
void search();/*查找模块*/
void main(){
while (1) /*一次完成无数条记录的输入*/
{
int n;
printf("\n\t*******************欢迎使用通讯录系统************************\n\n");
printf("\n\t创建,请按1");
printf("\n\t添加,请按2");
printf("\n\t查找,请按3");
printf("\n\t修改,请按4");
printf("\n\t输出,请按5");
printf("\n\t删除,请按6");
printf("\n\t退出,请按0");
printf("\n\t*************************************************************\n\n");
printf("\n请选择(0--5): ");
scanf("%d", &n);
if (n <= 6 && n >= 0)
{
switch (n)
{
case 1:creat(); break;
case 2:add(); break;
case 3:search(); break;
case 4:modify(); break;
case 5:output(); break;
case 6:del(); break;
case 0:exit(1);
}
printf("\n\n操作完成,请再次选择!");
}
else
printf("\n\n选择错误,请再次选择!");
}
}
查找模块:
void search(){
struct person one;
int k, j = 0;
if ((fp = fopen(dir_name, "r")) == NULL)
{
printf("\n不能打开通讯录");
getchar();
exit(1);
}
printf("\n姓名查找请按1");
printf("\n分类查找请按2");
printf("\n单位查找请按3");
printf("\n请选择查找方式(按回车键输入): ");
scanf("%d", &k);
switch (k){
case 1:
{
char s_name[10]; int j;
printf("\n请输入姓名: ");
scanf("%s", s_name);
while (!feof(fp))
{
fscanf(fp, "%s%s%s%s%s%s%s%s", one.name, one.addr, one.work_place, one.fixed_telephone,
one.mobile_phone, one.e_mail, one.QQ, one.category);
if (!strcmp(s_name, one.name))
{
printf("\n已经查到此人,记录为: \n");
printf("\n%-10s%-20s%-20s%-15s%-15s%-20s%-15s%-10s", one.name, one.addr, one.work_place,
one.fixed_telephone, one.mobile_phone, one.e_mail, one.QQ, one.category);
j = 1;
}
}
if (!j) printf("\n对不起,通讯录中没有此人的记录");
fclose(fp);
}
break;
case 2:
{
char s_category[10];
printf("\n请输入类别: ");
scanf("%s", s_category);
while (!feof(fp))
{
fscanf(fp, "%s%s%s%s%s%s%s%s", one.name, one.addr, one.work_place, one.fixed_telephone,
one.mobile_phone, one.e_mail, one.QQ, one.category);
if (!strcmp(s_category, one.category))
{
printf("\n已经查到此类人,记录为: \n");
printf("\n%-10s%-20s%-20s%-15s%-15s%-20s%-15s%-10s", one.name, one.addr, one.work_place,
one.fixed_telephone, one.mobile_phone, one.e_mail, one.QQ, one.category);
j = 1;
}
}
if (!j) printf("\n对不起,通讯录中没有此类人的记录");
fclose(fp);
}
break;
case 3:
{
char s_workplace[20];
printf("\n请输入工作单位 : ");
scanf("%s", s_workplace);
while (!feof(fp))
{
fscanf(fp, "%s%s%s%s%s%s%s%s", one.name, one.addr, one.work_place,
one.fixed_telephone, one.mobile_phone, one.e_mail, one.QQ, one.category);
if (!strcmp(s_workplace, one.work_place))
{
printf("\n已经查到此单位,记录为:\n");
printf("\n%-10s%-20s%-20s%-15s%-15s%-20s%-15s%-10s", one.name, one.addr, one.work_place,
one.fixed_telephone, one.mobile_phone, one.e_mail, one.QQ, one.category);
j = 1;
}
}
if (!j) printf("\n对不起,通讯录中没有此单位的记录");
fclose(fp);
}
break;
}
}
修改模块:
void modify(){
struct person one;
int k = 0;
long st;
char name_modify[10];
printf("\n请你输入要修改人的姓名: ");
scanf("%s", name_modify);
if ((fp = fopen(dir_name, "r+")) == NULL)
{
printf("\n不能打开通讯录!");
getchar();
exit(1);
}
while (!feof(fp))
{
st = ftell(fp); /*跟踪地址*/
fscanf(fp, "%s%s%s%s%s%s%s%s\n", one.name, one.addr, one.work_place, one.fixed_telephone,
one.mobile_phone, one.e_mail, one.QQ, one.category);
if (!strcmp(name_modify, one.name)){
k = 1;
break;
}
}
if (k)
{
printf("\n该名字已找到,他(她)的记录是:\n");
printf("%-10s%-20s%-20s%-15s%-15s%-20s%-15s%-10s", one.name, one.addr, one.work_place,
one.fixed_telephone, one.mobile_phone, one.e_mail, one.QQ, one.category);
printf("\n请输入新的姓名、住址、工作(或学习)单位、固定电话、手机号码、邮箱、QQ以及分类。请输入:\n");
scanf("%s%s%s%s%s%s%s%s", one.name, one.addr, one.work_place, one.fixed_telephone,
one.mobile_phone, one.e_mail, one.QQ, one.category);
fseek(fp, st, 0); /*找到修改的地址*/
fprintf(fp, "%-10s%-20s%-20s%-15s%-15s%-20s%-15s%-10s\n", one.name, one.addr, one.work_place,
one.fixed_telephone, one.mobile_phone, one.e_mail, one.QQ, one.category);
printf("\n已修改!");
}
else
printf("\n对不起,通讯录中没有此人的记录。");
fclose(fp);
}