I am trying to program my own hangman game without refrencing other programs as a way to get back into programming.
Right now I am trying to program a structure that will hold all of the letters that will be alphabetized and displayed for the user. In the middle of trying to realloc i got this error
34 67 C:\Users\hanna\Documents\C Codes\Testing Hangman.cpp [Error] invalid conversion from 'void*' to 'Guess*' [-fpermissive]
Here is the code I am working with right now:
#include <ctime>
#include <stdio.h>
#include <iostream>
#include<stdlib.h>
#include <cstdlib> //has rand function
using std::cout;
using std::cin;
struct Guess {
char Letter[1];
};
int count = 0;
struct Guess*guessKeeper;
int main()
{
char choice;
cout << "Do you want to add another guess? \n";
cin >> choice;
cout << choice << "\n";
if (choice == 'y')
{
struct Guess newGuess;
cout << "What is your guess? \n";
cin >> newGuess.Letter;
guessKeeper = realloc(guessKeeper,(count+1)*sizeof(struct Guess));
count++;
guessKeeper[count-1] = newGuess;
cout << "Do you want to add another guess? \n";
cin >> choice;
};
free(guessKeeper); //Free Memory
}
Any recomendations on how to alphabetize would also be appretiated.
I have tried refrencing other online tutorials and some of my old code from my college classes; it is why I landed on structures as I have an old assignment that had used a structure and has code for alphabetizing I was hoping to refrence.