| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1793 人关注过本帖
标题:新手有问题想请教,一段比较简单的代码
取消只看楼主 加入收藏
qssssss
Rank: 1
等 级:新手上路
帖 子:105
专家分:0
注 册:2017-4-3
结帖率:25%
收藏
已结贴  问题点数:20 回复次数:8 
新手有问题想请教,一段比较简单的代码
我不知道我输出的数组为什么一直错
int main(int argc, char *argv[])
{
    void SIZEINPUT(int nbounds, char* bndnames, double* boundarycoeffs);
    int nbounds = 3;
    char* bndnames[] = { "line_x","line_xy_1","line_xy_1" };
    double coeffs[9];
    int j;
    SIZEINPUT(nbounds, bndnames, coeffs);
    for (j = 0; j < 9; j++) {printf("\n  %f    \n", coeffs[j]);
     }
}
void SIZEINPUT(int nbounds, char* bndnames, double* boundarycoeffs)
{
    int i;
    double radius1 = 0.2;
    double radius2 = 0.45;
    double radius3 = 0.46;
    double radius4 = 0.5;
    double radius5 = 0.8;
    double hwidth = 0.8;


    for (i = 0; i<nbounds; i++) {
        if (bndnames[i] == "circle_1")
        {
            boundarycoeffs[i * 3] = 0.0;
            boundarycoeffs[i * 3 + 1] = 0.0;
            boundarycoeffs[i * 3 + 2] = radius1;
        }
        else if (bndnames[i] == "circle_2")
        {
            boundarycoeffs[i * 3] = 0.0;
            boundarycoeffs[i * 3 + 1] = 0.0;
            boundarycoeffs[i * 3 + 2] = radius2;
        }
        else if (bndnames[i] == "circle_3")
        {
            boundarycoeffs[i * 3] = 0.0;
            boundarycoeffs[i * 3 + 1] = 0.0;
            boundarycoeffs[i * 3 + 2] = radius3;
        }

        else if (bndnames[i] == "circle_4")
        {
            boundarycoeffs[i * 3] = 0.0;
            boundarycoeffs[i * 3 + 1] = 0.0;
            boundarycoeffs[i * 3 + 2] = radius4;
        }

        else if (bndnames[i] == "circle_5")
        {
            boundarycoeffs[i] = 0.0;
            boundarycoeffs[i + 1] = 0.0;
            boundarycoeffs[i + 2] = radius5;
        }
        else if (bndnames[i] == "line_x")
        {
            boundarycoeffs[i * 3] = 1.0;
            boundarycoeffs[i * 3 + 1] = 0.0;
            boundarycoeffs[i * 3 + 2] = 0.0;
        }
        else if (bndnames[i] == "line_y")
        {
            boundarycoeffs[i * 3] = 0.0;
            boundarycoeffs[i * 3 + 1] = 1.0;
            boundarycoeffs[i * 3 + 2] = 0.0;
        }
        else if (bndnames[i] == "line_xy_1")
        {
            boundarycoeffs[i * 3] = 1.0;
            boundarycoeffs[i * 3 + 1] = -1.0;
            boundarycoeffs[i * 3 + 2] = 0.0;
        }
        else if (bndnames[i] == "line_xy_2")
        {
            boundarycoeffs[i * 3] = 1.0;
            boundarycoeffs[i * 3 + 1] = 1.0;
            boundarycoeffs[i * 3 + 2] = 0.0;
        }
        else if (bndnames[i] == "line_x_1")
        {
            boundarycoeffs[i * 3] = 1.0;
            boundarycoeffs[i * 3 + 1] = 0.0;
            boundarycoeffs[i * 3 + 2] = hwidth;
        }
        else if (bndnames[i] == "line_x_2")
        {
            boundarycoeffs[i] = 1.0;
            boundarycoeffs[i * 3 + 1] = 0.0;
            boundarycoeffs[i * 3 + 2] = -hwidth;
        }
        else if (bndnames[i] == "line_y_1")
        {
            boundarycoeffs[i * 3] = 0.0;
            boundarycoeffs[i * 3 + 1] = 1.0;
            boundarycoeffs[i * 3 + 2] = hwidth;
        }
        else if (bndnames[i] == "line_y_2")
        {
            boundarycoeffs[i * 3] = 0.0;
            boundarycoeffs[i * 3 + 1] = 1.0;
            boundarycoeffs[i * 3 + 2] = -hwidth;
        }
        else
        {

            printf("\n error! \n");

        }
    }
}
搜索更多相关主题的帖子: double 
2017-04-03 14:09
qssssss
Rank: 1
等 级:新手上路
帖 子:105
专家分:0
注 册:2017-4-3
收藏
得分:0 
我一直输出的是error值没赋上去
2017-04-03 14:28
qssssss
Rank: 1
等 级:新手上路
帖 子:105
专家分:0
注 册:2017-4-3
收藏
得分:0 
有没有大神帮下忙的,真的感谢,很急
2017-04-03 14:45
qssssss
Rank: 1
等 级:新手上路
帖 子:105
专家分:0
注 册:2017-4-3
收藏
得分:0 
回复 4楼 初学编程的人
通过编译了但是我也不知道对不对因为我本身因为做一些别的,要利用C语言编程,就只能边做边学,你能指导下我错在哪吗
2017-04-03 14:58
qssssss
Rank: 1
等 级:新手上路
帖 子:105
专家分:0
注 册:2017-4-3
收藏
得分:0 
回复 6楼 renkejun1942
字符串的大小是什么意思啊?我刚刚试着用了一下这个函数可是编译虽然过了但是程序运行不出来
2017-04-03 15:08
qssssss
Rank: 1
等 级:新手上路
帖 子:105
专家分:0
注 册:2017-4-3
收藏
得分:0 
回复 8楼 renkejun1942
不好意思。。。我现在只改了if语句的第一个,你能帮我看下吗谢谢
int main(int argc, char *argv[])
{
    void SIZEINPUT(int nbounds, char* bndnames, double* boundarycoeffs);
    int nbounds = 3;
    char* bndnames[] = { "circle_1","line_x","line_xy_1" };
    double coeffs[9];
    int j;
    int k;
    SIZEINPUT(nbounds, bndnames, coeffs);
    for (j = 0; j < 9; j++) {
        printf("\n  %f    \n", coeffs[j]);
    }
    for (k = 0; k < 3; k++) {
            printf("\n   %s   \n", bndnames[k]);
        }

   
   

}
void SIZEINPUT(int nbounds, char* bndnames, double* boundarycoeffs)
{
    int i;
    double radius1 = 0.2;
    double radius2 = 0.45;
    double radius3 = 0.46;
    double radius4 = 0.5;
    double radius5 = 0.8;
    double hwidth = 0.8;


    for (i = 0; i<nbounds; i++) {
        if (!strcmp(bndnames[i], "circle_1"))
        {
            boundarycoeffs[i * 3] = 0.0;
            boundarycoeffs[i * 3 + 1] = 0.0;
            boundarycoeffs[i * 3 + 2] = radius1;
        }
        else if (bndnames[i] == "circle_2")
        {
            boundarycoeffs[i * 3] = 0.0;
            boundarycoeffs[i * 3 + 1] = 0.0;
            boundarycoeffs[i * 3 + 2] = radius2;
        }
        else if (bndnames[i] == "circle_3")
        {
            boundarycoeffs[i * 3] = 0.0;
            boundarycoeffs[i * 3 + 1] = 0.0;
            boundarycoeffs[i * 3 + 2] = radius3;
        }

        else if (bndnames[i] == "circle_4")
        {
            boundarycoeffs[i * 3] = 0.0;
            boundarycoeffs[i * 3 + 1] = 0.0;
            boundarycoeffs[i * 3 + 2] = radius4;
        }

        else if (bndnames[i] == "circle_5")
        {
            boundarycoeffs[i] = 0.0;
            boundarycoeffs[i + 1] = 0.0;
            boundarycoeffs[i + 2] = radius5;
        }
        else if (bndnames[i] == "line_x")
        {
            boundarycoeffs[i * 3] = 1.0;
            boundarycoeffs[i * 3 + 1] = 0.0;
            boundarycoeffs[i * 3 + 2] = 0.0;
        }
        else if (bndnames[i] == "line_y")
        {
            boundarycoeffs[i * 3] = 0.0;
            boundarycoeffs[i * 3 + 1] = 1.0;
            boundarycoeffs[i * 3 + 2] = 0.0;
        }
        else if (bndnames[i] == "line_xy_1")
        {
            boundarycoeffs[i * 3] = 1.0;
            boundarycoeffs[i * 3 + 1] = -1.0;
            boundarycoeffs[i * 3 + 2] = 0.0;
        }
        else if (bndnames[i] == "line_xy_2")
        {
            boundarycoeffs[i * 3] = 1.0;
            boundarycoeffs[i * 3 + 1] = 1.0;
            boundarycoeffs[i * 3 + 2] = 0.0;
        }
        else if (bndnames[i] == "line_x_1")
        {
            boundarycoeffs[i * 3] = 1.0;
            boundarycoeffs[i * 3 + 1] = 0.0;
            boundarycoeffs[i * 3 + 2] = hwidth;
        }
        else if (bndnames[i] == "line_x_2")
        {
            boundarycoeffs[i] = 1.0;
            boundarycoeffs[i * 3 + 1] = 0.0;
            boundarycoeffs[i * 3 + 2] = -hwidth;
        }
        else if (bndnames[i] == "line_y_1")
        {
            boundarycoeffs[i * 3] = 0.0;
            boundarycoeffs[i * 3 + 1] = 1.0;
            boundarycoeffs[i * 3 + 2] = hwidth;
        }
        else if (bndnames[i] == "line_y_2")
        {
            boundarycoeffs[i * 3] = 0.0;
            boundarycoeffs[i * 3 + 1] = 1.0;
            boundarycoeffs[i * 3 + 2] = -hwidth;
        }
        else
        {

            printf("\n error! \n");

        }
    }
}
2017-04-03 15:15
qssssss
Rank: 1
等 级:新手上路
帖 子:105
专家分:0
注 册:2017-4-3
收藏
得分:0 
回复 10楼 renkejun1942
嗯谢谢
2017-04-03 15:17
qssssss
Rank: 1
等 级:新手上路
帖 子:105
专家分:0
注 册:2017-4-3
收藏
得分:0 
回复 12楼 renkejun1942
非常感谢!好像在子函数那里,char那里必须要两个*号
2017-04-03 15:31
qssssss
Rank: 1
等 级:新手上路
帖 子:105
专家分:0
注 册:2017-4-3
收藏
得分:0 
回复 14楼 renkejun1942
嗯嗯真的很谢谢你
2017-04-03 15:38
快速回复:新手有问题想请教,一段比较简单的代码
数据加载中...
 
   



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

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