| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 287 人关注过本帖
标题:这神马情况!
取消只看楼主 加入收藏
神龙赖了
Rank: 10Rank: 10Rank: 10
来 自:萨塔星
等 级:青峰侠
威 望:2
帖 子:711
专家分:1788
注 册:2012-10-13
结帖率:97.22%
收藏
已结贴  问题点数:20 回复次数:1 
这神马情况!
程序代码:
void show(double number[], int count, unsigned int j)
{
    char str[12] = "%";  //格式化字符宽度值
    int i = 1;

    printf("count == %d\nstr == %s\n",count,str);
    do
    {
        str[i++] = '0'+count%10;
    }while(count/= 10 >0);

    str[i] = '\0';
    strcat(str,"lf");

    printf("%s\n",str);

    for(i=0;i<j;i++)
    {
        if(i%5==0)
            printf("\n");
        printf(str,number[i]);
    }
}
count在printf()输出的时候还是12,可在do{}while中竟然成了乱码
程序代码:
#include <stdio.h>
#include <string.h>

void show(double number[], int count, int i);

int main(void)
{
    double number[12] = {0};
    int j = 0;
    int i = 0;
    char answer = 'n';

    printf("Input:\n");
    do
    {
        scanf("%lf",&number[i++]);
        printf("Do you want to enter another?(y/n):");
        scanf(" %c",&answer);
    }while(i<12 && answer == 'y');
    printf("请指示字符宽度:");
    scanf("%d",&j);
    show(number,j,i);
    printf("\n");
    return 0;
}
这是main()函数
检查发现前面都没有问题

 do
    {
        str[i++] = '0'+count%10;
    }while(count/= 10 >0);

在这里面count的值变成了839248924之类的坑爹的数字
是我格式用错了吗?不会吧
各位大牛可以调试一下
如果找出错误了请帮忙讲解一下,谢谢。


元方,你怎么看?
元方:太坑爹了!!!
搜索更多相关主题的帖子: 神马 
2012-11-30 23:48
神龙赖了
Rank: 10Rank: 10Rank: 10
来 自:萨塔星
等 级:青峰侠
威 望:2
帖 子:711
专家分:1788
注 册:2012-10-13
收藏
得分:0 
2楼正确,可能是优先级不同,导致10与0先比较,然后返回1
不过count为什么会变成乱码呢?
有些错误?这个...我没有发现
能不能给点提示啊

I have not failed completely
2012-12-01 11:34
快速回复:这神马情况!
数据加载中...
 
   



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

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