LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1025|回复: 10

请帮看看这个APUE的8-17的程序错在哪里?

[复制链接]
发表于 2004-1-5 22:44:26 | 显示全部楼层 |阅读模式

  1. # cat -n 8.17.c
  2.      1  #include <sys/types.h>
  3.      2  #include <sys/acct.h>
  4.      3  #include "ourhdr.h"
  5.      4  #define ACCTFILE "/var/adm/pacct"
  6.      5  static unsigned long compt2ulong(comp_t);
  7.      6  int
  8.      7  main(void)
  9.      8  {
  10.      9    struct acct     acdata;
  11.     10    FILE            *fp;
  12.     11    if((fp=fopen(ACCTFILE,"r"))==NULL)
  13.     12        err_sys("cat not open %s",ACCTFILE);
  14.     13    while(fread(&acdata,sizeof(acdata),1,fp)==1) {
  15.     14        printf("%-*.*s e= %61d , chars = %71d,"
  16.     15               "stat= %3u: %c %c %c %c\n",sizeof(acdata.ac_comm),
  17.     16                sizeof(acdata.ac_comm),acdata.ac_comm,
  18.     17                compt2ulong(acdata.ac_etime),compt2ulong(acdata.ac_io),
  19.     18                (unsigned char) acdata.ac_stat,
  20.     19  #ifdef ACORE  /* SVR4 does not define ACORE */
  21.     20                 acdata.ac_flag & ACORE ? 'D' : ' ',
  22.     21  #else
  23.     22                                               ' ',
  24.     23  #endif
  25.     24  #ifdef AXSIG    /* SVR4 does not define AXSIG */
  26.     25                 acdata.ac_flag & AXSIG ? 'X' : ' ',
  27.     26  #else
  28.     27                                                ' ',
  29.     28  #endif
  30.     29                 acdata.ac_flag & AFORK ? 'F' : ' ',
  31.     30                 acdata.ac_flag & ASU   ? 'S' : ' ');
  32.     31    }
  33.     32    if(ferror(fp))
  34.     33      err_sys("read error");
  35.     34      exit(0);
  36.     35    }
  37.     36  static unsigned long
  38.     37  compt2ulong(comp_t comptime)  /* conert comp_t to unsigned long */
  39.     38  {
  40.     39    unsigned long val;
  41.     40    int           exp;
  42.     41    val=comptime & 01777;                 /* 13-bit fraction */
  43.     42    exp=(comptime >> 13 ) & 7 ;           /* 3-bit exponent (0-7) */
  44.     43    while(exp--> 0)
  45.     44        val *=8;
  46.     45    return(val);
  47.     46  }
  48.     47
复制代码

#gcc -c 8.17.c
8.17.c: In function `main':
8.17.c:18: structure has no member named `ac_stat'

:help :help :thank
 楼主| 发表于 2004-1-5 23:10:05 | 显示全部楼层
把char ac_stat;加进/usr/include/sys/acct.h就行了。
发表于 2004-1-7 13:42:08 | 显示全部楼层
。。。。
你随便改人家结构,编译虽然过了,得到的结果会对么
 楼主| 发表于 2004-1-7 16:25:01 | 显示全部楼层
谢谢你的提醒~~怎么办?是不是要同时修改~`features.h,sys/types.h,time.h或者其它的头文件?我就懂这么多了!!
发表于 2004-1-8 13:48:58 | 显示全部楼层
acdata下面没有ac_stat这个成员
你这个结果是怎么定义的。unix还是linux下定义的?
还是自己定义的?
发表于 2004-1-8 15:11:08 | 显示全部楼层
我想你应该改你的代码,去掉ac_stat的使用
发表于 2004-1-9 22:00:12 | 显示全部楼层
读书不要太死了,Linux/UNIX就是这样,每种系统都有一点差异
 楼主| 发表于 2004-1-10 11:02:43 | 显示全部楼层
最初由 libinary 发表
读书不要太死了,Linux/UNIX就是这样,每种系统都有一点差异


不懂你的意思!! 现在怎么办?难道缺少这一项功能?
发表于 2004-1-10 20:58:52 | 显示全部楼层
你看看sys/acct.h的struct acct,里面有一个u_int32_t ac_exitcode
发表于 2004-1-13 10:21:10 | 显示全部楼层
作者的系统是bsd,你的是linux吧
毕竟两种系统它的结构设置不一样的啦
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表