I am trying to set elements of a set at an index to 1 if an array contains those indices as its elements. Array size is 20 i.e. index 0 to 19
For ex -
int myArray[5] = {1,4,2}; //user input or statically defined in driver(main)
int set[] = {0,1,1,0,1}; //successfully set in constructor
IntegerSet intObj(set);//At a point, program stops execution. Any idea why?
Here is the partial code
//integerset.h
class IntegerSet{
public :
IntegerSet( int [] );
.....
private :
int set[20];
};
//integerset.cpp (header files included)
IntegerSet :: IntegerSet( int arr[]){
for(int i = 0; i <20; i++) //works fine (printed "test" in loop)
set[i] = 0; //if not this then garbage elems set
for ( int i = 0; arr[i] != '\0' ; i++ ) //works fine. (printed "test" in loop)
set [arr[i]] = 1;
for ( int i = 0; i < 20; i++ ) //program stops execution here
cout<<i<<"\t"<<set[i]<<"\n"; //tried to print "test" in loop,program crashed
}
//main.cpp (header files included)
int main(){
int a[] = {1,3,0,12,14,15,'\0'}; // premature end??
IntegerSet obj2(a);
system("pause");
return 0;
}
setas variable name.set [arr[i]] = 1;what is this , could someone explain?