我的功能已被注释掉,因为我首先尝试解决此问题><。但是当我尝试将数组传递给函数时,编译会出现错误消息。
error: cannot convert ‘char*’ to ‘char (*)[7][49]’ for argument ‘1’ to
‘void save(char (*)[7][49])’
这在我的代码中出现在第63:61,67:46和70:36行。
//Header
#include <iostream>
#include <fstream>
using namespace std;
//function prototype
/*
Name: deal
Process: takes cards from file into 3d array and 2d array
Input: array name (int),2d array name (int)
Output: none
Dependencies: none
*/
void deal ( char tablue [7][7][49] , char wastePile [24][24]);
/*
Name: displayCards
Process: Displays cards from array to screen
Input: tablue array (char)
Output to screen: The cards in a solitaire display
Dependencies: None
*/
void displayCards ( char tabalue [7][7][49]);
/*
Name: save
Process: Save tablue to a file
Input: tablue (char)
Output: None
Depnencies: None
*/
void save ( char tablaue [7][7][49] );
// global constants
ofstream fout;
ifstream fin;
//main program
int main()
{
//initialize variables
bool menu = true;
char choice;
char tablaue [7][7][49], wastePile [24][24];
//switch menu
// display options
cout<< "G.ame" << endl << "Q.uit" << endl;
//menu
while ( menu == true )
{
// get user choice
cin >> choice;
// switch
switch (choice)
{
// if game
case 'G':
//get cards from file
//deal cards to three "deminsion array" and into waste pile
// function deal
deal ( &tablaue [7][7][49], &wastePile [24][24]);
//display cards on screen
// function displayCards
displayCards ( &tablaue [7][7][49]);
//save tablaue
save ( &tablaue [7][7][49]);
// pause screen
//system pause
// break case
break;
//if quit
case 'Q':
// end switch
menu = false;
//break case
break;
}
}
// display exit screen
cout<< "Thanks for playing";
//end program
return 0;
}
//Functions
void deal (char tablue [7][7][49], char wastePile [24][24])
{
/*/ initialize variables
char card [40];
char space [10];
int rowI, colI, cardI;
// open file
fin.open("card1.txt");
// prime loop
fin << card;
//take in cards
while (fin.good())
{
fin << SPACE;
// fill in array
for ( rowI=0, rowI<7, rowI++)
{
for ( colI=0, colI<7, colI++)
{
for ( cardI=0, cardI<49, cardI++)
{
// check to see if slot should be empty
if ( rowI < colI)
{
tablue[rowI][colI][cardI] = "EMPTY";
}
// put card in slot
else
{
tablue[rowI][colI][cardI] = card;
}
}
}
}
//fill waste pile
for (rowI=0, rowI<24, rowI++)
{
wastePile [rowI] = card;
}
}*/
}
void displayCards ( char tablue[7][7][49])
{
/*/ initialize variables
int rowI, colI, cardI;
// make space
cout<< endl << endl << " ";
// display card
for (rowI =0, rowI<7, rowI++)
{
for (colI=0, colI<7, colI++)
{
for (cardI=0, cardI<7, cardI++)
{
//check for empty slot
if ( tablue[rowI][colI][cardI] != "EMPTY")
{
cout << tablue [rowI][colI][cardI];
}
else
{
cout<< " ";
}
//print space
cout<<" ";
}
}
}*/
}
void save ( char tablue [7][7][49] )
{
/*
*/
}
答案 0 :(得分:5)
将数组作为参数传入时,不需要&
或数组大小。简单地传递名称就足够了,只要你的bas数组大小和类型被正确地声明,从上面的代码中可以看出它们就是这样。
IE:
deal ( tablaue, wastePile );