Getting array from another function...

Im trying to make this so when it saves the file, it goes to another function and grabs the whole array then prints it to another file. Here is the save file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <fstream>
#include <string>

using namespace std;
int printmap(int cDir, char write);
char statvault(char stat, char acc, char val[]);

void savegame()
{
 ofstream qWrite("Save.txt");
 int posX = printmap('x', 0);
 int posY = printmap('y', 0);
 int posZ = printmap('z', 0);
 char* cName[8];
 cName = statvault('N', 2, cName);
 qWrite << cName << endl;
 qWrite << posX << endl;
 qWrite << posY << endl;
 qWrite << posZ << endl;
 
 qWrite.close();
}


And then here is the function its trying to get the data from:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
char cName[8];
using namespace std;

char* statvault(char stat, char acc, char val[])
{
 if(acc == 1)//Write to stats
 {
  if(stat == 'N')
  {
   for(int i = 0; i < 9; i++)
   {
    cName[i] = val[i];
   }
  }
 }
 else if(acc == 2)//Read stats
 {
  if(stat == 'N')
  {
   return(cName);
  }
 }
}


Here is the error I got though:
16 C:\Users\Todd\Desktop\Tests\Black Skies Projects\saving.cpp cannot convert `char**' to `char*' for argument `3' to `char* statvault(char, char, char*)'
for the line that says cName = statvault('N', 2, cName);
statvault takes a character array (a.k.a. C string) as its third input (char[]). cName is an array of C strings (char*[]). Why it listed that you're dealing with char** and char* is because arrays are specialized pointers (char[] == char* after initialization).

-Albatross
So exactly how can I make it so I can make Saving go into statvault, read the name, bring it back, then put it into a file? This is my first time attempting to move an array from function to function... Im not a person that learns stuff in order, I jump around alot then slowly bring everything together. Its a really bad habit.
Topic archived. No new replies allowed.