| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1253 人关注过本帖
标题:大神求助,c源程序在VS2013上编译时各种语法错误,该如何修改,弄了一早上, ...
只看楼主 加入收藏
谨之羁绊
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2015-6-30
结帖率:0
收藏
已结贴  问题点数:20 回复次数:3 
大神求助,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);
}
搜索更多相关主题的帖子: category 手机号码 include 固定电话 person 
2015-06-30 10:27
谨之羁绊
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2015-6-30
收藏
得分:0 
2015-06-30 10:41
诸葛欧阳
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:流年
等 级:贵宾
威 望:82
帖 子:2790
专家分:14619
注 册:2014-10-16
收藏
得分:10 
VS上的语法有些不太一样,你上网查查吧

一片落叶掉进了回忆的流年。
2015-06-30 12:51
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9024
专家分:54030
注 册:2011-1-18
收藏
得分:10 
既不肯贴完整代码
又不肯贴错误信息
2015-06-30 15:09
快速回复:大神求助,c源程序在VS2013上编译时各种语法错误,该如何修改,弄了一 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.028112 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved