fuyichen20 2022-03-12 16:50 采纳率: 100%
浏览 157
已结题

Dev-Cpp 报错[Error] ld returned 1 exit status,这是因为什么?

Dev-Cpp报错[Error] ld returned 1 exit status

事先说明一下,我把黑色的运行框关闭了也是一样的结果,应该是不因为有程序正在运行才返回[Error] ld returned 1 exit status的。

代码粘出,共大家帮忙检查
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
#include<cstdio>
#include<ctime>
#include<cstdlib>
#include<algorithm>
using namespace std;
#include<cstring>
using namespace std;
#include<iostream>
using namespace std;


const int MaxN = 1e4 + 10;
int tmax, tmin, d[MaxN], e[MaxN];
double tav;
int * fun3(int * const buf); 
void dispArr(int *arr, int n);
const int arrlen = 195;


int Random() {
    for (int i = 0; i < 195; ++i) {
        d[i] = i + 1;
    }
    int index, temp, rest = 195;
    for (int i = 0; i < 195; ++i) {
        index = rand() % rest;
        e[i] = d[index];
        temp = d[index];
        d[index] = d[rest - 1];
        d[rest - 1] = temp;
        rest--;
    }
    return Random();
}


int *fun3(int* const buf) {
    if (buf == NULL) {
        cerr << "error: null ptr @buf" << endl;
        return NULL;
    }
    for (int i = 0; i < arrlen; i++) {
        buf[i] = i;
    }
    return buf;
    for (int i = 0; i <= arrlen; i++) {
        buf[i] = 0;
    }
}

void dispArr(int *arr) {
    for (int i = 0; i < 195; i++) {
        Random();
    }
    for (int i = 0; i <= 195; i++) {
        arr[i] = 0;
    }
}

double dt = 0.95;
int t = 0, a = 0, b[228], l = 8, S = 4, n[250], c[MaxN];
double sum = 0;

int mmcs() {
    memset(n, 0, 250);
    int *arr2 = new int[arrlen];
    dispArr(arr2, arrlen);
    delete arr2;
    for (int i = 0; i <= 194; i++) {
        b[i] = Random();
        for (int i = 0; i <= 194; i++) {
            d[i] = 0;
            e[i] = 0;
        }
    }
    for (int i = 195; i <= 227; i++) {
        b[i] = 0;
    }

    for (int j = 0; j <= 100000; j++) {
        for (int i = 226; i >= 0; i--) {
            if (ceil(b[i] / 6) == i - 194) {
                if (n[i] == S + l) {
                    b[i] = 0;
                    n[i] = 0;
                } else {
                    n[i]++;
                }
            } else {
                if (b[i + 1] == 0) {
                    b[i + 1] = b[i];
                    b[i] = 0;
                }
            }
        }
        t++;
        for (int i = 226; i >= 0; i--) {
            if (b[i] != 0) {
                a = 1;
            }
        }
        if (a == 0) {
            break;
        }
        a = 0;
        c[j] = t * dt;
        cout<<c[j]<<endl;
    }
    t = 0;
}


int main() {
    for (int i = 0; i <= 9; i++) {
        Random();
        mmcs();
        for (int i = 0; i < 195; ++i) {
            d[i] = 0;
            e[i] = 0;
        }
    }
    for (int i = 0; i <= 9; i++) {
        sum += c[i];
    }
    for(int i=0;i<=9;i++){
        tmax=0;
        tmin=10000;
        if(tmax<c[i]){
            tmax=c[i];
        }
        if(tmin>c[i]){
            tmin=c[i];
        }
    }
    tav = sum / 10;
    cout << "tmax=" << tmax << ",tmin=" << tmin << " tav=" << tav << endl;
    return 0;
}

运行结果及报错内容

报错内容:}(没错,就是一个大括号)
具体存在于函数mmcs的最后一行:

int mmcs() {
    memset(n, 0, 250);
    int *arr2 = new int[arrlen];
    dispArr(arr2, arrlen);
    delete arr2;
    for (int i = 0; i <= 194; i++) {
        b[i] = Random();
        for (int i = 0; i <= 194; i++) {
            d[i] = 0;
            e[i] = 0;
        }
    }
    for (int i = 195; i <= 227; i++) {
        b[i] = 0;
    }

    for (int j = 0; j <= 100000; j++) {
        for (int i = 226; i >= 0; i--) {
            if (ceil(b[i] / 6) == i - 194) {
                if (n[i] == S + l) {
                    b[i] = 0;
                    n[i] = 0;
                } else {
                    n[i]++;
                }
            } else {
                if (b[i + 1] == 0) {
                    b[i + 1] = b[i];
                    b[i] = 0;
                }
            }
        }
        t++;
        for (int i = 226; i >= 0; i--) {
            if (b[i] != 0) {
                a = 1;
            }
        }
        if (a == 0) {
            break;
        }
        a = 0;
        c[j] = t * dt;
        cout<<c[j]<<endl;
    }
    t = 0;
}

关闭了所有的运行框且尝试过重新编译,没有反应。

希望各位能够帮忙解答,谢谢!

  • 写回答

1条回答 默认 最新

  • Code_流苏 C/C++领域优质创作者 2022-03-12 16:53
    关注

    有程序正在运行才返回[Error] ld returned 1 exit status的
    很多情况都是这个原因,题主可以把软件关了,加速球加速一下,等大概十几秒左右,然后再打开,运行一下试试。

    希望对题主有所帮助,可以的话,帮忙点个采纳!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 3月21日
  • 已采纳回答 3月13日
  • 创建了问题 3月12日

悬赏问题

  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器