GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 04-Sep-2008, 18:25
zhbcool zhbcool is offline
New Member
 
Join Date: Sep 2008
Posts: 1
zhbcool is on a distinguished road

2D Dynamic Array


I am having issues writing a program.. I have attached the directions that I have gotten.. currently I am getting the following error: 1>c:\users\zoheb\documents\visual studio 2008\projects\dynamic 2d array\dynamic 2d array\dynamic 2d array.cpp(20) : error C2440: '=' : cannot convert from 'int *' to 'int'

Here is my code
CPP / C++ / C Code:
#include <iostream>
#include <fstream>

using namespace std;

int main () {

	int height, width;
	int sum,row,column,value;
	int **array;
	
	ifstream inFile("matrix1.dat");
	
	if(!inFile) {
		cerr << "File matrix1.dat could not be opened!";
	}
	
	inFile >> height >> width;
	cout << height << ' '<< width << endl;
	**array = &array[height][width];
	
	while(inFile) {
        inFile >> row >> column >> value;
      array[row][column] = value;
	}
		
	//calculate the sum of each row

	for (int i=0; i<height; i++) {
		sum = 0;
		for (int j=0; j<width; j++) {
			sum += array[i][j];
		}
		cout << i << " = " << sum << endl;
	}
	
	//calculate the sum of each column

	for (int i = 0; i < width; i++) {
		sum = 0;
		for (int j = 0; j < height; j++) {
			sum += array[j][i];
		}
		cout << i << " = " << sum << endl;
	}
	for (int i = 0; i < height; i++){
          delete[] array[i];
     delete[] array;
	}

}
Attached Images
File Type: jpg comp_csi_assign_1.jpg (55.0 KB, 10 views)
  #2  
Old 04-Sep-2008, 20:26
Studly Studly is offline
Junior Member
 
Join Date: Mar 2008
Posts: 31
Studly will become famous soon enough

Re: 2D Dynamic Array


It looks like you are trying to use a variable named array as a int **. "array" is a keyword and you should try to avoid using it as a variable name. You can create a 2d array by:

CPP / C++ / C Code:
	
int** myarray;

myarray = new int*[height];
for(int i = 0; i<height; i++)
	myarray[i] = new int [width];
 
 

Recent GIDBlogAccepted for Ph.D. program by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
where is the problem and can you fix it (php) oggie MySQL / PHP Forum 8 14-Apr-2008 16:08
Getting a line error in register oggie MySQL / PHP Forum 5 13-Apr-2008 17:16
Dynamic Array and Input/Output Files OnlyCurious C++ Forum 11 08-Jan-2007 14:49
Need help deleting the last element in the array headphone69 C++ Forum 2 15-Mar-2006 20:31
problem reading to a dynamic array noamfrie C Programming Language 9 02-Jan-2005 19:35

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 00:33.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.