-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])
{
/*
*/
}
annnnd其中線是這些? – djechlin
關閉瀏覽器。抓住K&R C.閱讀。 – 2012-09-05 19:55:32
你可能想重新考慮使用向量,因爲你標記它C++ –