| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 955 人关注过本帖
标题:Segmentation fault (core dumped)
只看楼主 加入收藏
GreasyFish
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2017-7-27
收藏
 问题点数:0 回复次数:3 
Segmentation fault (core dumped)

#include<stdio.h>
#include<utmp.h>
#include<fcntl.h>
#include<unistd.h>

#define SHOWHOST            /* include remote machine on output */

int main()
{
        struct utmp current_record;     /* read info int here */
        int         utmpfd;             /* read from this descriptor */
        int         reclen = sizeof(current_record);

        if(( utmpfd = open(UTMP_FILE, O_RDONLY)) == -1) {
                perror(UTMP_FILE);      /* UTMP_FILE is in utmp.h */
                exit(1);
        }

        while(read(utmpfd, &current_record, reclen) == reclen)
                show_info(&current_record);
        close(utmpfd);
        return 0;                       /* went ok */
}
show_info(struct utmp *utbufp)
{
        if( utbufp->ut_type != USER_PROCESS )
                return;
        printf("% -8.8s", utbufp->ut_name);     /* the logname */
        printf(" ");                            /* a space */
        printf("% -8.8s", utbufp->ut_line);     /* the tty */
        printf(" ");
        showtime(utbufp->ut_time);
    #ifdef SHOWHOST
        printf("( % s)", utbufp->ut_host);      /* the host */
    #endif
        printf("\n");                           /* new line */
}

void showtime( long timeval )
{
        char *cp;
        cp = ctime(&timeval);
        printf("%12.12s",cp+4);
}
代码如上,调试问题如下:
图片附件: 游客没有浏览图片的权限,请 登录注册

有大神给个回复嘛,系统是ubuntu16.04,gcc编译

搜索更多相关主题的帖子: Segmentation include int printf the 
2017-07-27 17:06
虾米小小小
Rank: 3Rank: 3
等 级:论坛游侠
威 望:2
帖 子:30
专家分:135
注 册:2017-7-22
收藏
得分:0 
utmp.h文件呢?

2017-07-27 18:50
GreasyFish
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2017-7-27
收藏
得分:0 
回复 2楼 虾米小小小
utmp.h文件
图片附件: 游客没有浏览图片的权限,请 登录注册
图片附件: 游客没有浏览图片的权限,请 登录注册

你的意思是字长的问题?
2017-07-28 08:58
GreasyFish
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2017-7-27
收藏
得分:0 
回复 2楼 虾米小小小
解决了,谢谢
2017-07-28 09:10
快速回复:Segmentation fault (core dumped)
数据加载中...
 
   



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

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