必承其重 | 欲带皇冠 2018-10-22 22:53 采纳率: 0%
浏览 385

为什么我的命令窗口在传递标记时显示一个总线错误?

I'm currently working on a school project where we are required to do some sequencing, but in my code however I am getting a bus error while running the double precision but not the single precision.

#include <stdio.h>
#include <string.h>

void singleprecision()
{
    float x[21];
    x[1] = 11.0f/2.0f; x[2] = 61.0f/11.0f;

    int k = 3;
    for (; k <= 10; k++)
    {
        x[k] = 111.0f-(1130.0f - 3000.0f/x[k-2])/x[k-1];
        printf("x[%d]:%f\n",k,x[k]);
    }
}



void doubleprecision()
{
    double x[21];
    x[1]=11.0/2.0;
    x[2] = 61.0/11.0;

    int k = 3;
    for(; k<=20; k++);
    {
        x[k] = 111.0 - (1130.0 - 30000.0/x[k-2])/x[k-1];
        printf("x[%d]:%lf\n",k,x[k]);
    }
}


int main(int argc, char *argv[])
{ 
    int i = 0; // will there be double precision used based on the g input in the command line

    if (argc == 2 && strcmp(argv[1],"-d")==0) // checking for -g input on the command line
    {
        doubleprecision();
        printf("Double Precision is being used \n");
    }
    else 
    {
       printf("Single Precision is being used \n");
       singleprecision();
    }

   return 0;
}

Any help would be wonderful in order to assist me in getting through this challenge and understanding it.

I am running on a remote linux system and compiling with gcc, it compiles fine but likewise fails when in double precision.

转载于:https://stackoverflow.com/questions/52938764/why-does-my-command-window-present-a-bus-error-while-passing-a-tag-through

  • 写回答

1条回答 默认 最新

  • larry*wei 2018-10-23 00:25
    关注

    in the function: doubleprecision() remove the extraneous ; from the end of the statement: for(; k<=20; k++) Then the code runs with no problems.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。