Well this is my first attempt at receiving help from the community. I am currently a Computer Science major at a University and am in my second semester. My current teacher has not been of much help outside of the class so I am hoping this community can.
Before the haters come at me, this is an assignment, but I am not asking for the assignment to be done for me. I am merely asking a question about an error I'm receiving. I want to understand what's going wrong, not have it done for me.
I am attempting to assign "randomChoice" as the array index of the "listOfWords" array then copy "listOfWords[randomChoice] to "selectedWord". I am not sure if it is that I do not fully understand the use of strcopy() or something wrong with my arrays. Hopefully you guys can help!
This is my error:
And my code:
hangman.cc: In function ‘void SelectWord(char (*), int, char*):
hangman.cc:84: error: invalid conversion from 'char' to 'const char*'
#include <iostream>#include <fstream>
using namespace std;
const int MAX_WORDS = 80;
const int MAX_USED = 80;
void ReadWords (char listOfWords[MAX_USED], int numOfWords, ifstream& inFile);
void SelectWord (char listOfWords[MAX_WORDS][MAX_USED], int numOfWords, char selectedWord[MAX_WORDS]);
//Call the functions to use in the program
int main (int argc, char *argv)
inFile.open(argv); //Open file
assert(inFile); //Check if file opened correctly
ReadWords (listOfWords, numOfWords, inFile);
SelectWord (listOfWords, numOfWords, selectedWord);
//Function will read in words from data file into a 2D array
void ReadWords (char listOfWords[MAX_WORDS][MAX_USED], int numOfWords, ifstream& inFile)
numOfWords = 0;
while ((inFile.peek() != EOF) && (numOfWords < MAX_WORDS))
inFile.getline (listOfWords[numOfWords], 100, '\n');
//Debugging - Array content check
for(int i = 0; i < numOfWords; i++)
cout << listOfWords[i] << endl;
void SelectWord (char listOfWords[MAX_WORDS][MAX_USED], int numOfWords, char selectedWord[MAX_WORDS])
randomChoice = rand()%numOfWords;
//Debugging - Generating random number check
//cout << randomChoice << endl;