how do i change a struct to an array, string, or pointer?

Jul 14, 2015 at 11:34pm
Hi i need help converting my struct to something i can use in C program. I understand that structs are introduces in C++ so i was wondering how i could change that. any help is greatly appreciated :)

#include <iostream>
#include <fstream>

using namespace std;

struct Board
{
int values[81]; //Stores board values
bool isFixedValue[81]; //Keeps track of what numbers can be modified
bool isPossibleValue[81][9]; //decides what values are possible for certain square
int coordinates;
};

void getFileName(char fileName[]);
bool getBoard(char fileName[], Board &mainBoard);
bool validateBoard(Board board);
void interact(Board &mainBoard);
void displayMenu();
void displayBoard(Board board);
char getOption();

int getCoordinates(bool isFixedValue[]);
int getNewValue(Board &board);
bool canChange(Board mainBoard, int coordinates, int value);
bool anyDuplicates(int board[], int coordinates, int value);
void editSquare(int board[], int coordinates, int value);
bool checkPossibles(Board &newBoard);
/*float solve(Board &newBoard);
bool bruteForce(Board &board);*/
bool isSolved(Board board);
void clearBoard(Board &board);


//gets the filename, loads board, and checks to see if opened properly then interacts with the user.
int main(int argc,char *argv[])
{
char fileName[256];
Board mainBoard;

//Get FileName and read board
getFileName(fileName);

if (!getBoard(fileName, mainBoard))
cout << "Error: Unable to open file " << fileName << endl;

//Validate Board and show menu
else
if (validateBoard(mainBoard))
{
displayMenu();
displayBoard(mainBoard);
interact(mainBoard);
}

// system("PAUSE");
return 0;
}
Jul 15, 2015 at 1:27am
Actually, structs came from C and were carried over into C++. C++ just added the class keyword as an alias of the struct keyword.
Jul 15, 2015 at 5:09am
LB

so are you saying that instead of naming is Struct board to just name it class board?
Jul 15, 2015 at 7:35am
Sorry, I think we are misunderstanding each other. I thought you wanted to go backward from C++ to C?
Jul 15, 2015 at 11:08am
Your code is basically a c program (as LB stated struct is actually C). You just cannot use cout.

Use printf instead:

http://www.cplusplus.com/reference/cstdio/printf/?kw=printf
Topic archived. No new replies allowed.