can't find source file error

Hi,
Can you tell me what I should be looking for when this error occurred:
"Can't find a source file at "malloc.c"
Locate the file or edit the source lookup path to include its location."

The occurred when this call arrayPtr = new int[indexSize]; this call is done multiple times before w/in main w/o error. Then it pops up on the last call !

closed account (28poGNh0)
Can you give us all you code
thanks in advance...

* iadrv.h
*
* Created on: Jul 16, 2013
* Author: nhat
*/

#ifndef IADRV_H_
#define IADRV_H_

#include "IntArray.h"

int main();
void test1();
void test2();
void test3();
void test4();
void test5();
void test6();

#endif /* IADRV_H_ */


/*
* iadrv.cpp
*
* Created on: Jul 16, 2013
* Author: nhat
*/

#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdlib.h>
#include "iadrv.h"
using namespace std;

ofstream csis;

int main() {
csis.open("csis.txt");
test1();
test2();
test3();
test4();
test5();
test6();
}


void test1() {

IntArray a(10);
for(int i = a.low(); i <= a.high(); i++) {
a[i] = i * 10;
}
a.setName('a');
cout << a << endl;
wait();
}


void test2() {

IntArray b(-3,6);
for(int i = b.low(); i <= b.high(); i++){
b[i] = i * 10;
}
b.setName('b');
cout << b << endl;

wait();
}

void test3() {

IntArray c(6, 8);
for(int i = c.low(); i <= c.high(); i++)
c[i] = i * 10; // &currentArray[x]
c.setName('c');
cout << c << endl;
wait();
}

void test4() {

IntArray d(5, 5);
for(int i = d.low(); i <= d.high(); i++)
d[i] = i * 10;
d.setName('d');
cout << d << endl;
wait();
}

void test5() {

IntArray z;
for(int i = z.low(); i <= z.high(); i++)
z[i] = i * 10;
z.setName('z');
cout << z << endl;
wait();

}

void test6() {

IntArray c(2, 10);
for(int i = c.low(); i <= c.high(); i++)
c[i] = i * 10;
c.setName('c');
cout << c << endl;

IntArray e(c);
e.setName('e');
cout << e << endl;
wait();
}

/*
* IntArray.h
*
* Created on: Jul 16, 2013
* Author: nhat
*/

#ifndef INTARRAY_H_
#define INTARRAY_H_

class IntArray {
private:
char arrayName;
int * arrayPtr;
int lowIdx;
int highIdx;
int indexSize;
int ptrIncrement;

public:
// constructors for possible array types.
IntArray (); // array default to 0-9
IntArray (int); //single int, elements from 0 to -Int.
IntArray (int, int); //array with lower and upper indices.
// this one will test for single element array (i.e IntArrya A(5,5);
IntArray (const IntArray &obj); // array declare with another object array
~IntArray();

//overloading operators.
int& operator[](int i); // allows index range checnking
friend std::ostream& operator<<(std::ostream& os, IntArray& I); // allows the contents of an array to be ouput.
void operator+=(IntArray); // allows the sum of two arrays to be assigned to a first array
IntArray operator+(IntArray); // allow the sum of the two arrays to be assigned to the third array.

private: // functions

void indiceCheck(); // verify array index is valid.
void initArray();

public: //functions
int high(); // return the high index of array
int low(); // return low inderx of array
void setIdxRange(int l, int h);
void setName(char); // set the arrayName variable to current array.
char getName(); // return array name
void wait();
};


#endif /* INTARRAY_H_ */


/*
* IntArray.cpp
*
* Created on: Jul 16, 2013
* Author: nhat
*/
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include "IntArray.h"

using namespace std;

// ARRAY CONSTRUCTORS.
// init all element[0] to null.

IntArray::IntArray() {
setIdxRange(1,10);
indexSize = 9;
initArray();
}

IntArray::IntArray(int a) {
// set private variable low and high
setIdxRange(1,a);
indexSize = a - 1;
initArray();
}

IntArray::IntArray(int a, int b) {

setIdxRange(a,b);
indexSize = b - a;
initArray();
}

IntArray::IntArray(const IntArray &obj) {
// make a copy of obj.

indexSize = obj.indexSize;
arrayPtr = new int[indexSize];
lowIdx = obj.lowIdx;
highIdx = obj.highIdx;
ptrIncrement = 0;
// deep copy of pointer.
for(int x=0; x<=indexSize; x++) {
arrayPtr[x] = obj.arrayPtr[x];
}
}


// DESTRUCTOR
IntArray::~IntArray(){
delete [] arrayPtr;
}
// OPERATORS OVERLOAD
int& IntArray::operator[] (int i){
// all arrays start with index 0. set arrayPtr to return first index
// next loop, add one to the index.
int temp = 0;
temp = ptrIncrement;
ptrIncrement++;
// cout<<"temp: " << temp << " ptrIncrement: " << ptrIncrement << endl;
return(arrayPtr[temp]);
}

std::ostream& operator<<(std::ostream& os, IntArray& a) {
// reset ptrIncrement to 0 for this [] overload.
a.ptrIncrement = 0;

for (int i = a.low(); i <= a.high(); i++) {
cout << a.getName()<<"[" << i << "] = " << a[a.ptrIncrement] << " "<<endl;
}
return(os);
}

void operator+=(IntArray a, IntArray b) {

}

IntArray operator+(IntArray a) {
IntArray x;

return(x);
}
// FUNCTIONS
void IntArray::setName(char n) {
arrayName = n;
}

char IntArray::getName() {
return this->arrayName;
}

int IntArray::low() {
return(lowIdx);
}

int IntArray::high() {
return(highIdx);
}

void IntArray::wait() {
char buf;

cout << "Press any key to continue. " << endl;
cin.get(buf);
}

void IntArray::initArray() {
// set ptrIncrement to 0 (first index)
ptrIncrement = 0;

// size of index,start and end index are set in constructor.
// create a dynamic index.
// set initial elements to 0

arrayPtr = new int[indexSize];

for(int x=0; x<=indexSize; x++)
arrayPtr[x] = 0;
}


void IntArray::setIdxRange(int l, int h) {
lowIdx = l;
highIdx = h;
}
closed account (28poGNh0)
I brought couple of changes to your program It works fine even I dont have your csis.txt

I think your progblem is in testx functions because you call a member function of IntArray class in wrong way

use a.wait(); instead of wait();

1
2
3
4
5
6
7
8
9
10
11
void test1()
{
    IntArray a(10);
    for(int i = a.low(); i <= a.high(); i++)
    {
        a[i] = i * 10;
    }
    a.setName('a');
    cout << a << endl;
    a.wait();
}


Please use code tags next time

hope that help
sorry, I should have included the wait(), it's actually part of the iadrv.cpp file, not part of the IntArray.cpp.

But here is an error I've found running the program with gdb.

Program received signal SIGSEGV, Segmentation fault.
0xb7d8d175 in malloc_consolidate (av=0xb7ebc440) at malloc.c:4257
4257 malloc.c: No such file or directory.

my question is what file or directory is it looking for ?
closed account (28poGNh0)
The compiler show this error
No such file or directory.

when we include a header that does not exists and unknow by the compiler
for exp if you write # include "malloc.c" or # include <malloc.c>

that's what I think ,On what IDE do you program?
I wrote it on Eclipse Indigo (ubuntu)...but I ran the gdb via Xterm.
closed account (28poGNh0)
I never worked on Eclipse Indigo I use currently VS c++ and code::blocks I am sorry I cant give you something I dont know

can you me a link to download this compiler?
go to eclipse.com you can download it there.
I think I am closing in on this @#$@ :) I ran valgrind to track down memory usage and I got the same error every time testx is called...
Topic archived. No new replies allowed.