Thread: Kernell32.dll Error

  1. #1
    Registered User mouse163's Avatar
    Join Date
    Dec 2002
    Posts
    49

    Kernell32.dll Error

    hey all...this code compiles and runs correctly...all except a Kernell32.dll error that pops up during the run. Anyone see
    a pile of dlls on the stack inappropriately that would cause this?
    (It's one of my early 2d array progs that i did in my 1st class).
    I never was able to debug the error out.
    thanks a bunch, it may teach me something about how to trouble-shoot these and other errors
    mouse163
    Code:
    #include<iostream>
    #include<iomanip>
    #include<fstream> 
    using namespace std; 
    
    const int kcols = 6;
    const int krows = 4;
    
    void Loadit(int arr2d[][kcols], int rows);
    void Printit_a(int arr2d[][kcols], int rows);
    void Printit_b(int arr2d[][kcols], int rows);
    void Maxit(int arr2d[][kcols], int rows);
    void RsumL(int arr2d[][kcols], int rows);
    void CsumS(int arr2d[][kcols], int rows);
    
    
     ofstream outfile("A:\\0F1031c.txt"); 
    
    int main ()
    {
     
       
        if(!outfile)
    	{ 
            cerr << "Cannot open output file" << endl; 
            return 1; 
        } 
    	
    
    
         int arr2d[][kcols]={0};
    
    	   Loadit(arr2d, krows);
           Printit_a(arr2d, krows);
    	   Printit_b(arr2d, krows);
    	   Maxit(arr2d, krows);
    	   RsumL(arr2d, krows);
    	   CsumS(arr2d, krows);
    
    	
    	outfile.close(); 
    
    	return 0; 
    
    } 
    
    //Part1 : Function definition: Load
    		void Loadit(int arr2d[][kcols], int rows)
    {
    		ifstream infile("A:\\IF1031.txt"); 
        	if(!infile)
    		{ 
            	cerr << "Cannot open input file" << endl;
    		} //inf
    	
    
    		for ( int i = 0; i < rows; i++ ){
    			for ( int j = 0; j < kcols; j++ ){
    			        infile >> arr2d[i][j];
    			      
    		}//j loop
    }
    		infile.close(); 
    
    }// fx end
    
    //Part2a : Function definition: Print(ordered pairs)
    		void Printit_a(int arr2d[][kcols], int rows)
    {
    
    		outfile << "\n\n";
    		outfile<< setw(60) 
    			   << "Part 1 & 2 - Loaded & Printed Array as an Ordered Pair:" 
    			   << "\n\n" << endl;
    	    outfile<< setw(30) << endl;
    
    		for ( int i = 0; i < krows; i++ )
    		{
    			for ( int j = 0; j < kcols; j++ )
    			{
    				outfile << "arr2d[" << i << "]" << "[" << j << "] =";
    				outfile<< arr2d[i][j]<< endl << setw(30);
    
    			 }// j loop	
    		 }//i loop
    
    		        outfile << "\n\n";
    }// fx end
    			
    	
    //Part2b : Function definition: Print (matrix)
    		void Printit_b(int arr2d[][kcols], int rows)
    {
    
    		outfile << "\n\n";
    		outfile<< setw(50) 
    			   << "Loaded & Printed Array as a Matrix:" 
    			   << "\n\n" << endl;
    		outfile<< setw(23) << "";
    
    		
    			for (int j = 0; j < kcols; j++ )
    			{
    			outfile << j << setw(4);
    			} // j loop
    
    				outfile << endl;
    				outfile<<setw(3*kcols)<<" ";
    				for (int line = 0;line < kcols;line++)
    				{
    					outfile<<"-----";
    				}//line
    					outfile << endl;
    
    					for (int i = 0; i < krows; i++)
    					{
    						outfile<< setw(20) << i << "|" << setw(2);
    
    						for ( int j = 0; j < kcols; j++ )
    						{
    								outfile<< setw(4) << arr2d[i][j]<< setw(6);
    						}//j loop
    									outfile << endl;
    				}//i loop
    
    
    		outfile << "\n\n-------------------------------------------------------------------\n";
    }// fx end
    
    
    
    
    //Part3 : Function definition: Largest Int & Address
    	
    		void Maxit(int arr2d[][kcols], int rows)
    {
    		
    		outfile << "\n\n";
    		outfile<< setw(57) 
    		       << "Part 3 - Largest Int in the Array and it's Location:" 
    			   << "\n\n" << endl;
    
    				int maxi = 0;
    				int maxj = 0;
    				for (int i = 0; i < krows; i++)
    				{
    					for (int j = 0; j < kcols; j++)
    					{
    						if (arr2d[i][j] > arr2d[maxi][maxj])
    						{
    							maxi = i;
    							maxj = j;
    						}// if 
    
    
    					}//j loop
    
    
    				}//i loop
    
    		outfile<< setw (25) << "The Max Value is " 
    			   << arr2d[maxi][maxj];
    		outfile<< " it occurs at arr2d[" 
    			   << maxi <<"][" << maxj << "]" << endl;						
    	    outfile << "\n\n-------------------------------------------------------------------\n";
    
    }// fx end
    
    
    
    
    //Part4 : Function definition: Row Sums / Largest Sum
    
    		void RsumL(int arr2d[][kcols], int rows)
    {
    
    		outfile << "\n\n";
    		outfile<< setw(62) 
    			   << "Part 4 - Sum of each Row & the Row with the largest Sum: " 
    			   << "\n\n" << endl;
    
    
    			
    			int maxi = 0;
    			int maxsum = 0;
    			for (int i = 0; i < krows; i++)
    			{
    				int sum = 0;
    				for (int j = 0; j < kcols; j++)
    				{
    					sum += arr2d[i][j];
    
    				}//j loop
    
    		outfile << setw(30) 
    			    << "Sum of Row "
    			    << i<< "  is " << sum << endl;
    
    					if (sum > maxsum)
    					{
    						maxsum = sum; // assign max sum
    						maxi = i;   // call row w/ maxsum
    					}//if 
    					
    
    			}//i loop
    
    		outfile << setw(42) 
    			    << " The Max Sum is in Row  " 
    				<< maxi << endl;
    		outfile << setw(29) << " The Sum = " 
    			    << maxsum << endl;
    		outfile << "\n\n-------------------------------------------------------------------\n";
    
    
    }// fx end
    
    
    
    //Part5 : Function definition: Column Sums / Smallest Sum
    		void CsumS(int arr2d[][kcols], int rows)
    {
    		outfile << "\n\n";
    		outfile<< setw(69) << "Part 5 - Sum of each Column & the Column with the Smallest Sum: " << "\n\n" << endl;
    
    			
    			int minj = 0; 
    			int minsum = 32768;
    		
    
    			for (int j = 0; j < kcols; j++)
    			{
    				int sum = 0;
    
    				for (int i = 0; i < krows; i++)
    				{
    					sum += arr2d[i][j]; // for each row add one to the col sum
    		
    				}//i loop
    
    		outfile << setw(33) 
    				<< "Sum of Column "<< j 
    				<< "  is " << sum << endl;
    
    					if(sum < minsum)
    					{
    						minsum = sum; //assign min sum
    						minj = j; // call the col with the min sum
    
    					}// if 
    
    			}//j loop	
    		outfile << setw(45) 
    			    << " The Min Sum is in Column  " << minj << endl;
    		outfile << setw(29) << " The Sum = " 
    			    << minsum << endl;
    		outfile << "\n\n-------------------------------------------------------------------\n";
    	
    }//fx end

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    post your errors pls

  3. #3
    Registered User mouse163's Avatar
    Join Date
    Dec 2002
    Posts
    49

    no errors

    i don't get any errors.
    the program compiles perfectly AND my output is perfect...
    except when it is writing to the outfile (or even if I cout it to the screen) i get this error:

    http://scuba22.freeyellow.com/1.JPG

    i say OK and the program continues to run and finish...


    this is the data from my infile :
    1 29 38 94 50 67
    37 899 10 119 121 138
    11 15 203 401 222 109
    2 94 55 5 35 21

    what do you think?
    thanks alot

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >int main ()
    >{
    >
    >
    > if(!outfile)
    > {
    > cerr << "Cannot open output file" << endl;
    > return 1;
    > }
    >
    >
    >
    > int arr2d[][kcols]={0};

    You have to give it both dimensions when you declare the array.
    int arr2d[krows][kcols]={0};
    Another option is to declare it dynamically.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM