调试运行时出现奇怪的崩溃程序(Eclipse C++)
Weird crashing program while debug runs smoothly (Eclipse C++)
我正在为我的大学算法数学课编写一个程序,我正在使用Win 7(x64(,Eclipse Oxygen.1a版本(4.7.1a(和MinGW 6.3.0。
每当我构建并运行程序时,它都会崩溃,窗口声称"Abgabe3.exe停止工作",但是当尝试使用调试器和断点查找问题时,我逐步执行整个程序,它完成没有错误...
我剥离了有问题的功能未使用的所有内容,并将所有内容复制到一个单独的文件中,然后出现了确切的问题。也许有人知道我身边发生了什么。^^
#include <math.h> /* pow, sqrt */
#include <iostream> /* cin, cout */
#include <new> /* new */
#include <string> /* string */
#include <stdlib.h> /* srand, rand */
#include <time.h> /* time */
using namespace std;
void NORM(double* res, double* x, int n){
res[0] = 0.0;
for(int i = 0; i < n; i++){
res[0] += pow(x[i], 2);
}
res[0] = sqrt(res[0]);
}
void initRand(double* x, int n){
srand (time(NULL) * rand());
for(int i = 0; i < n; i++){
x[i] = (((double) rand()) / ((double) RAND_MAX));
}
}
void createArray(double* &x, int n){
if (n > 0){
x = new double[n];
initRand(x, n);
}
}
void printArray(double* x, int n){
if (x != NULL){
cout<<"(n";
for(int i = 0; i < n; i++){
if(i+1 == n) cout<<x[i];
else if ((i % 5) == 0) cout<<x[i];
else if ( ((i+1) % 5) == 0 ){
cout<<", "<<x[i]<<"n";
}
else {
cout<<", "<<x[i];
}
}
cout<<"n)n";
}
else cout<<"nError: pointer = NULLn";
}
unsigned long long int bin(unsigned int n, unsigned int k){
unsigned long long res = 1;
if(k == 0) return 1;
else if( n >= k){
for(unsigned long long int i = 1; i <= k; i++){
res *= (n + 1 - i) / i;
}
}
else return 0;
return res;
}
void newArray(double** x, unsigned int v, unsigned int n){
for(unsigned int i = 0; i < v; i++){
double* ptr = x[i];
createArray(ptr,n);
x[i] = ptr;
}
}
void experiment(double** vektorArray){
unsigned int n = 10, v = 20;
cout<<"Dimension n = "<<n<<"nAnzahl Versuche v = "<<v<<endl;
//Erstellen der Vektoren
cout<<"Erstellen - starten";
vektorArray = new double*[n];
newArray(vektorArray, v, n);
cout<<"Erstellen - fertign";
for(unsigned int i = 0; i < v; i++){
if(i%10 == 0) printArray(vektorArray[i], n);
}
}
int main(int argc, char** argv){
double** vektorArray = NULL;
experiment(vektorArray);
return 0;
}
vektorArray = new double*[n];
创建了一个大小为 n
的数组,但是
void newArray(double** x, unsigned int v, unsigned int n)
{
for (unsigned int i = 0; i < v; i++)
{
double* ptr = x[i];
createArray(ptr, n);
x[i] = ptr;
}
}
和
for (unsigned int i = 0; i < v; i++)
{
if (i % 10 == 0)
printArray(vektorArray[i], n);
}
用 v
索引该数组。看起来你交叉了你的变量。强烈建议为变量提供更好、更具描述性的名称,以帮助使其更明显。
相关文章:
- 如何在使用 SDL2 的 Eclipse 中构建 c++ 程序
- 如何将 Python.h 库添加到 eclipse 以用于C++程序?
- 如何从终端运行用 eclipse 编写的 c++ 程序
- 如何在 eclipse 中将标准输入从控制台更改为另一个程序
- Eclipse CDT:传递具有相同文件扩展名的多个程序参数
- C++程序在 Xcode 中运行,但不是 Eclipse
- 在后台记录 Eclipse IDE 调用的应用程序列表
- 在Ubuntu上使用Eclipse时,将新的第三方库与C 程序联系起来
- 调试运行时出现奇怪的崩溃程序(Eclipse C++)
- 无法在Eclipse中编译带有输入和输出的C 程序
- Eclipse 在检查语法时看不到包含文件,但在构建或运行应用程序时会看到
- 当qt插件在Windows中不起作用时,如何在eclipse cdt中创建qt应用程序
- 在 Eclipse 中使用 JNI 构建 OpenCV 应用程序
- Eclipse Ubuntu 中的“程序不是可识别的可执行文件”错误
- Eclipse PTP挂起OpenMPI应用程序的启动调试会话
- 为什么我的 c++ 程序在 Eclipse 中没有输出而终止,但在 Visual Studio 中工作
- 运行C 程序Eclipse(无需构建)的错误
- 我尝试运行我在 eclipse 中创建的 c++ 应用程序(它的.exe),它说"libgcc_s_dw2-1.dll丢失并尝试重新安装
- 在Eclipse Indigo上构建C++程序时出错
- 使用matlab引擎编译c++程序eclipse