| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 633 人关注过本帖
标题:assignment from incompatible pointer type 不知道怎么解决(103,和110行 ...
只看楼主 加入收藏
AC_bang
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2015-1-14
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:2 
assignment from incompatible pointer type 不知道怎么解决(103,和110行的警告)
/*二、随机文件的读写操作

1、已知职工信息包含:职工号、姓名、基本工资、津贴、水电费和实发工资,请从键盘输入10人的信息保存在 wage.dat文件中,并将职工信息依次显示在屏幕上。

 2、打开wage.dat文件,输出职工号为偶数的职工信息;

 3、打开wage.dat文件,按实发工资从低到高排序,并将排序后的职工信息写到文件 wagesort.dat中,并显示排序后的职工信息。

struct employee{   int  number ;    char   name[10];    double jbgz;     double  jintie;     doube  sdfyong;     double  wage; }employer[10]; */

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

#define N 2

struct employee {
    int number;
    char name[10];
    int jbgz;
    int jintie;
    int sdf;
    int wage;
};

int main(void) {
    struct employee employer[N];
    char str[10];
    FILE *fp,*fp2;
    int i,j,temp;
    long record_len;
    record_len = sizeof(struct employee);
    printf("请输入10个职工的信息:\n");
    printf("职工号、姓名、基本工资、津贴、水电费和实发工资\n");
    for(i =0; i < N; i++) {
        scanf("%d %s %d %d %d ",&employer[i].number,employer[i].name,&employer[i].jbgz,&employer[i].jintie,&employer[i].sdf);
        employer[i].wage = employer[i].jbgz + employer[i].jintie - employer[i].sdf;
    }
    if((fp = fopen("wage.dat","wb")) == NULL)
         printf("File open error!\n");
    else {
        for(i = 0; i <= N; i++) {
            fwrite(&employer[i],record_len,1,fp);
        }
        fclose(fp);
    }
    //在屏幕上显示职工信息
    if((fp = fopen("wage.dat","rb")) == NULL)
        printf("File open error!\n");
    else {
        printf("%6s%10s%10s%10s%10s%10s\n","职工号","姓名","基本工资","津贴","水电费","实发工资");
        for(i =0; i < N; i++) {
            fread(&employer[i],record_len,1,fp);
            printf("%6d%10s%10d%10d%10d%10d\n",employer[i].number,employer[i].name,employer[i].jbgz,employer[i].jintie,employer[i].sdf,employer[i].wage);
        }
        fclose(fp);
    }
    if((fp = fopen("wage.dat","rb")) == NULL)
        printf("File open error!\n");
    else {
        printf("职工号为偶数的职工信息为:\n");
        printf("%6s%10s%10s%10s%10s%10s\n","职工号","姓名","基本工资","津贴","水电费","实发工资");
        for(i = 0; i < N; i+=2) {
            fseek(fp,i*record_len,0);
            fread(&employer[i],record_len,1,fp);
            printf("%6d%10s%10d%10d%10d%10d\n",employer[i].number,employer[i].name,employer[i].jbgz,employer[i].jintie,employer[i].sdf,employer[i].wage);
        }
        fclose(fp);
    }
    if((fp = fopen("wage.dat","rb")) == NULL)
        printf("File open error!\n");
    else {
        for(i = 0; i < N; i++)
            fread(&employer[i],record_len,1,fp);
        for(i = 0; i < N; i++)
            for(j = 0; j < N-1-i; j++) {
                if(employer[i].wage > employer[i+1].wage) {
                    temp = employer[i].number;
                    employer[i].number = employer[i+1].number;
                    employer[i+1].number = temp;

                    strcpy(str,employer[i].name);
                    strcpy(employer[i].name,employer[i+1].name);
                    strcpy(employer[i+1].name,str);

                    temp = employer[i].jbgz;
                    employer[i].jbgz = employer[i+1].jbgz;
                    employer[i+1].jbgz = temp;

                    temp = employer[i].jintie;
                    employer[i].jintie = employer[i+1].jintie;
                    employer[i+1].jintie = temp;

                    temp = employer[i].sdf;
                    employer[i].sdf = employer[i+1].sdf;
                    employer[i+1].sdf = temp;

                    temp = employer[i].wage;
                    employer[i].wage = employer[i+1].wage;
                    employer[i+1].wage = temp;
                }
            }
            if((fp2 = ("wagesort.dat","wb")) == NULL)                                              此行有警告
                printf("File open error!");
            else
                for(i = 0; i < N; i++)
                    fwrite(&employer[i],record_len,1,fp2);
            fclose(fp2);
            //在屏幕上显示排序后的职工信息
            if((fp2 = ("wagesort.dat","rb")) == NULL)                                               此行有警告
                printf("File open error!");
            else {
                printf("%6s%10s%10s%10s%10s%10s\n","职工号","姓名","基本工资","津贴","水电费","实发工资");
                for(i =0; i < N; i++) {
                    fread(&employer[i],record_len,1,fp);
                    printf("%6d%10s%10d%10d%10d%10d\n",employer[i].number,employer[i].name,employer[i].jbgz,employer[i].jintie,employer[i].sdf,employer[i].wage);
                }
            }
            fclose(fp2);
    }
    return 0;
}
可以运行,但会中途停止,求大神解答

搜索更多相关主题的帖子: employee include number 水电费 键盘 
2015-01-14 15:32
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:20 
你自己说那两行写的是什么?

授人以渔,不授人以鱼。
2015-01-14 15:36
AC_bang
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2015-1-14
收藏
得分:0 
我知道了。。。少了fopen,,,,SO 尴尬。。
2015-01-14 15:39
快速回复:assignment from incompatible pointer type 不知道怎么解决(103,和 ...
数据加载中...
 
   



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

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