找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 422|回复: 2

段错误!

[复制链接]

5

主题

3

回帖

0

积分

新手上路

积分
0
发表于 2013-6-11 12:51:28 | 显示全部楼层 |阅读模式
#include <stdio.h>
#define SEC_PER_MIN  60

int main(void)
{
    int sec,min;
    int left;
    sec  = 0;
    min  = 0;
    left = 0;

    printf("convert secs to min and secs\n");
    printf("Enter the number of secs(<=0 to quit):\n");

   
    scanf("%d",&sec);//这里为啥段错误?如何改?
    while( sec > 0 )
    {
        
        min  = sec / SEC_PER_MIN;
        left = sec % SEC_PER_MIN;
        printf("%d secs is %d mins and %sec.\n ", sec,min,left);
        printf("Enter next value (<=0 quit):\n");
        scanf("%d",&sec);
    }
   
    return 0;
}
调试后发现是scanf段错误,???

14

主题

65

回帖

0

积分

新手上路

积分
0
发表于 2013-6-11 13:35:53 | 显示全部楼层
printf("%d secs is %d mins and %d sec.\n ", sec,min,left);

3

主题

7

回帖

0

积分

新手上路

积分
0
发表于 2013-6-11 16:25:57 | 显示全部楼层
第22行:错误代码:      
printf("%d secs is %d mins and %sec.\n ", sec,min,left);
正确代码:
printf("%d secs is %d mins and %d.\n ", sec,min,left);
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

果子博客
扫码关注微信公众号

Archiver|手机版|小黑屋|风叶林

GMT+8, 2026-2-1 05:54 , Processed in 0.133321 second(s), 20 queries .

Powered by 风叶林

© 2001-2026 Discuz! Team.

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