Salü liebe foristen.
Kann mir jemand mit meinem Programm von der Arbeit helfen. Ich finde den Fehler einfach nicht. So langsam bin ich echt schon am verzweifeln. Es soll ein beliebig grosses 2 Dimensionales Array erstellt werden und das soll mit zufälligen werten gefüllt sein. Aber der compiler von code::blocks sagt das er irgendwas nicht zuweisen kann.
C:\Users\yasmin\Documents\Code\pointer\main.cpp||I n function 'int** makeNewMatrix(short unsigned int, short unsigned int)'
C:\Users\yasmin\Documents\Code\pointer\main.cpp|67 |error: lvalue required as left operand of assignment|
C:\Users\yasmin\Documents\Code\pointer\main.cpp|69 |error: invalid conversion from 'int' to 'int**' [-fpermissive]|
||=== Build finished: 2 errors, 0 warnings (0 minutes, 0 seconds) ===|
Was hat die Meldung zu bedeuten. Ich komm nicht weiter.
Code:
#include <iostream>
#include <cstdlib>
#include <cmath>
#define ARG 3
#define MAXI (2 << 15)
void coutMatrix(int **, unsigned short, unsigned short);
void deleteMatrix(int **, unsigned short);
int **makeNewMatrix(unsigned short, unsigned short);
int main(int argc, char *argv[])
{
int tmp[2];
short zeilen, spalten;
if (argc != ARG)
{
std::cout << "\nFehler: Zu wenig Argumente\n" << std::endl;
std::cout << argv[0] << " <Zeilenanzahl> <Spaltenanzahl>" << std::endl;
exit(EXIT_FAILURE);
}
spalten = zeilen ^= zeilen;
tmp[0] = atoi(argv[1])&((short)pow(sizeof(short), 0x10));
tmp[1] = atoi(argv[2])&((short)pow(sizeof(short), 0x10));
if (tmp[0] & 0x8000)
tmp[0] = ~tmp[0]+1;
if (tmp[1] & 0x8000)
tmp[1] = ~tmp[1]+1;
zeilen = tmp[0];
spalten = tmp[1];
int **vektor = makeNewMatrix(zeilen, spalten);
for (int i = 0; i < zeilen; ++i)
for (int j = 0; j < spalten; ++j)
vektor[i][j] = i+j;
coutMatrix(vektor, zeilen, spalten);
deleteMatrix(vektor, zeilen);
return EXIT_SUCCESS;
};
void coutMatrix(int **v, unsigned short z, unsigned short s)
{
for (unsigned short i = 0; i < z; ++i)
{
std::cout << "Zeile: " << i << std::endl;
for (unsigned short j = 0; j < s; ++j)
{
std::cout << "\tSpalte: " << j << " : ";
std::cout << v[i][j] << std::endl;
}
}
};
int **makeNewMatrix(unsigned short z, unsigned short s)
{
int **v = NULL;
v = (int**)malloc(sizeof(int*) * z);
for (unsigned short i = 0; i < z; ++i)
(v+i) = (int*)malloc(sizeof(int) * s);
return **v;
};
void deleteMatrix(int **v, unsigned short z)
{
for (unsigned short i = 0; i < z; ++i)
free(*(v+i));
free(v);
v = NULL;
};