-3

我的函数被注释掉了,因为我试图先解决这个问题><。但是当我尝试将我的数组传递给函数时,编译会出现一条错误消息。

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] )
{
/*

*/
}
4

1 回答 1

5

&将数组作为参数传递时,您不需要数组大小。只需传入名称就足够了,只要正确声明了您的 bas 数组大小和类型,从上面的代码中可以看出,它们就是。

IE:

deal ( tablaue, wastePile );
于 2012-09-05T19:50:58.977 回答