I'm a newbie at C++, but I tried to do my research.However I seem to be not able to figure out what is wrong in my code, probably not familiar with the syntax, that I can't find. Trying to do something bigger, just testing some theory.
Here I have filled a 2D array, put in a function Func(). Lets suppose I did something to it, then I want to retrieve it from there. I imagined I could extract an address to the first array of arrays, but I keep getting the same error.
#include <iostream>
#include <time.h>
#include <cstdlib>
#include <typeinfo>
using namespace std;
char(*)[15] Func(char A[15][15]) //Here is the problem
{
A[0][0]='O';
return A; //trying to return an address to the A[0]-1D array
}
int main() //This part isn't really important, just filling an 2-D array
{
char A[16][16];
int x,y;
for (y=0; y<=15;y++)
{
for(x=0;x<=15;x++)
{
if (3<=x<=12 and 3<=y<=12)
{
A[y][x]='*';
}
if (x==0 or x==15 or y==0 or y==15)
{
A[y][x]='#';
}
if ((x==2 and 2<=y<=13) or (x==13 and 2<=y<=13) or (y==2 and 2<=x<=13) or(y==13 and 2<=x<=13))
{
A[y][x]='#';
}
if (x==14 or y==14 or (x==1 and y==1))
{
A[y][x]='#';
}
}
}
for (int i=0,y=3, x=1; y<=12; y++, i++ )
{
char j='0'+i;
A[y][x]=j;
}
for (int i=0,y=1, x=3; x<=12; x++, i++)
{
char j='0'+i;
A[y][x]=j;
}
for (y=0; y<=15;y++)
{
for(x=0;x<=15;x++){
cout<<A[y][x];
}
cout<<endl;
}
char(*p)[15]=Func(A[15][15]); //here Im trying to assign pointer p to point to the first 1D array of 15x15 Array of A (To do pointer arithmetics later)
cout<<"p="<<p; //Just testing
return 0;
}
And I get this error:
expected unqualified-id before ')' token
expected initializer before 'Func'
Both directed at Func() function declaration line
Plus this error:
'Func' was not declared in this scope
Which is not pleasant too but less engaging than the previous ones, in my opinion.
I think the problem might be in the type of "A" (the pointer) or there is something I missed.
How can I fix the issues of this code? It feels like I have tried everything! Thank you.