标题:请教一下,编译报错error C2440: '=' : cannot convert from 'struct Table ...
只看楼主
琼羽
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2015-3-24
结帖率:80%
 问题点数:0 回复次数:3 
请教一下,编译报错error C2440: '=' : cannot convert from 'struct Table *' to 'struct main
#include<stdio.h>
#include<stdlib.h>
struct EngineerDuty
{
    char Duty[50];
    char Project[50];
    int ProjectNum;
};
struct Table
{
    char name[32];
    int age;
    char job[32];
    union DifferPart
    {
        int ClassCode;
        char Department[20];
        struct EngineerDuty EngDuty;
    }TeacherStudentEngineer;
};

void InputInfo(struct Table *InputTable,unsigned n)
{
    unsigned int i=0;
//    3sstruct Table *CopyInput=InputTable;
    printf("开始处理函数InputInfo()\n");
    for(;i<n;i++)
    {
        printf("请输入No.%d个人的姓名 年龄和工作:\n",i+1);
        scanf("%s %d %s",InputTable->name,
                        &InputTable->age,
                        InputTable->job);
        if('S'==InputTable->job[0]||'s'==InputTable->job[0])
        {
            printf("请输入学生的学号:\n");
            scanf("%d",&InputTable->TeacherStudentEngineer.ClassCode);
        }
        else
            if('T'==InputTable->job[0]||'t'==InputTable->job[0])
            {
                printf("请输入老师的系别:\n");
                scanf("%s",InputTable->TeacherStudentEngineer.Department);
            }
            if('E'==InputTable->job[0]||'e'==InputTable->job[0])
            {
                printf("请输入工程师的职责:\n");
                scanf("%s %s %d",InputTable->TeacherStudentEngineer.EngDuty.Duty,
                                 InputTable->TeacherStudentEngineer.EngDuty.Project,
                                 InputTable->TeacherStudentEngineer.EngDuty.ProjectNum);
            }
            InputTable++;
    }
}

void OutputInfo(struct Table *OutputTable,unsigned n)
{
    unsigned int i=0;
    printf("开始处理函数:OutputInfo()\n");
    for(;i<n;i++)
    {
    if('S'==OutputTable->job[0]||'s'==OutputTable->job[0])
        {
            printf("输出学生的信息:\n");
            printf("  name    age    job    classCode\n");
            printf(" %s  %d  %s  %d\n",OutputTable->name,
                                       OutputTable->age,
                                       OutputTable->job,
                                       OutputTable->TeacherStudentEngineer.ClassCode);
        }
        else
            if('T'==OutputTable->job[0]||'t'==OutputTable->job[0])
            {
                printf("输出老师的信息:\n");
                printf("  name    age    job    department\n");
                printf(" %s  %d  %s  %d\n",OutputTable->name,
                                           OutputTable->age,
                                           OutputTable->job,
                                           OutputTable->TeacherStudentEngineer.Department);
            }
            if('E'==OutputTable->job[0]||'e'==OutputTable->job[0])
            {
                printf("输出学生的信息:\n");
                printf("  name    age    job    duty    project    projectNum\n");
                printf(" %s  %d  %s  %s  %s  %d\n",OutputTable->name,
                                                   OutputTable->age,
                                                   OutputTable->job,
                                                   OutputTable->TeacherStudentEngineer.EngDuty.Duty,
                                                   OutputTable->TeacherStudentEngineer.EngDuty.Project,
                                                   OutputTable->TeacherStudentEngineer.EngDuty.ProjectNum);
            }
            OutputTable++;
    }
}

void main()
{
    int size=0;
    struct *TableOfTeaAndStuAndEng;
    struct *CopyTableOfTeaAndStuAndEng;
    size=sizeof(struct Table);
    printf("结构体Table的大小为:%d\n",size);
    TableOfTeaAndStuAndEng=(struct Table *)malloc(3*size);
    InputInfo(TableOfTeaAndStuAndEng,3);
    OutputInfo(TableOfTeaAndStuAndEng,3);
}
搜索更多相关主题的帖子: convert include cannot 
2015-04-26 15:38
琼羽
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2015-3-24
得分:0 
编译报错::\Documents and Settings\Administrator\桌面\VC6\Common\MSDev98\Bin\test.cpp(102) : error C2440: '=' : cannot convert from 'struct Table *' to 'struct main::$S1 *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
C:\Documents and Settings\Administrator\桌面\VC6\Common\MSDev98\Bin\test.cpp(103) : error C2664: 'InputInfo' : cannot convert parameter 1 from 'struct main::$S1 *' to 'struct Table *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
C:\Documents and Settings\Administrator\桌面\VC6\Common\MSDev98\Bin\test.cpp(104) : error C2664: 'OutputInfo' : cannot convert parameter 1 from 'struct main::$S1 *' to 'struct Table *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
执行 cl.exe 时出错.

test.exe - 1 error(s), 0 warning(s)
2015-04-26 15:41
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
得分:0 
把英文翻译出来就是答案

授人以渔,不授人以鱼。
2015-04-26 21:37
琼羽
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2015-3-24
得分:0 
求各位帮我看一下这个函数,如何使其保存的数据不会多出空格和换行
void SaveFile(struct Table *SaveDate, unsigned n)
{

    FILE *fp_rd = NULL;
    fp_rd = fopen("F:\\SaveDate.txt", "wt+");
    if (NULL == fp_rd)
    {
        ERROR("文件SaveDate.txt打开失败!");
    }
    else
    {
        INFO("文件SaveDate.txt打开成功!");
    }
    unsigned int i = 0;
    for (; i<n; i++, SaveDate++)
    {
        //fprintf(fp_rd, "   name     age    job");
        fprintf(fp_rd, " %7s  %4d  %8s ",
            SaveDate->name,
            SaveDate->age,
            SaveDate->job);
        if ('S' == SaveDate->job[0] || 's' == SaveDate->job[0])
        {
            fprintf(fp_rd, "  %12d\n",SaveDate->TeacherStudentEngineer.ClassCode);
        }
        else
            if ('T' == SaveDate->job[0] || 't' == SaveDate->job[0])
            {
                fprintf(fp_rd, "%12s\n",SaveDate->TeacherStudentEngineer.Department);
            }
        if ('E' == SaveDate->job[0] || 'e' == SaveDate->job[0])
        {
            fprintf(fp_rd, "%12s \n", SaveDate->TeacherStudentEngineer.Duty);
        }
        
    }
    i = fclose(fp_rd);
    if (0 == i)
    {
        INFO("文件关闭成功!");
    }
    else
    {
        ERROR("文件关闭失败!")
    }
}
2015-06-12 16:28



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-444514-1-1.html




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

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