2012-09-05 61 views
-3

我的功能已被注释掉,因为我试图首先解决此问题> <。但是,当我尝试将我的数组传递给函数时,编译出现错误消息。无法将char *转换为字符

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

*/ 
} 
+1

annnnd其中线是这些? – djechlin

+1

关闭浏览器。抓住K&R C.阅读。 – 2012-09-05 19:55:32

+0

你可能想重新考虑使用向量,因为你标记它C++ –

回答

5

当传递数组作为参数时,不需要&或数组大小。只要简单地传入名称就足够了,只要您的bas数组大小和类型被正确声明,从上面的代码看来,它们就是这样。

IE:

deal (tablaue, wastePile);