dev-c++ is giving me errors.
18 22 L:\SCHOOL\ Spring 2012\COMSC-048\Game Of Life.cpp [Error] invalid conversion from 'char' to 'const char*' [-fpermissive]
strcpy takes two parameters; both must be of type char*.
GetName claims to returns a char. A char is not char*.
As it is, GetName is actually a mess, as it returns file which is an array of char, and will be passed back as a char*, but you've written the prototype claiming it will return a char.
I see you're using Dev-c++. If you're using version 4.9.9.2 or earlier, that's a terrible choice.
strcpy takes two parameters; both must be of type char*.
GetName claims to returns a char. A char is not char*.
As it is, GetName is actually a mess, as it returns file which is an array of char, and will be passed back as a char*, but you've written the prototype claiming it will return a char.
I see you're using Dev-c++. If you're using version 4.9.9.2 or earlier, that's a terrible choice.
It's better, although you're still using strcpy, which is not great, and you're using proper C++ strings but converting them into arrays of char. Why not do this instead?
(2) The initial configuration will be read in from a file, which will be a 12 by 30 two-dimensional array of characters. The game board will be surrounded by all O's.
Seriously, why the insistence in your getname fnuction with taking C++ strings, which are easy and safe, and going out of your way to to them into unsafe, difficult arrays of char?
Need some help:
With what? Reading in?
1 2 3 4 5
while (notFinishedReadingEverythingIn)
{
myfile >> file;
file++;
}
That will fill the 2D array, if you read in 12*30 chars.
Unfortunately, because you're creating the 2D array as a local variable in the function GetName, when that function ends all that array will be reused for other things and you'll be left with a pointer that points at whatever has been written over the array.
Here is how our implementation will work:
(1) The program will ask the user to enter a filename from the console. (Just like the last assignment).
(2) The initial configuration will be read in from a file, which will be a 12 by 30 two-dimensional array of characters. The game board will be surrounded by all O's.
(3) The game will be played on 10 by 28 two-dimensional array. (Can you guess why?). A period ('.') will represent a dead cell and an 'X' will represent a live cell.
You will be severely penalized if your program does not have at least three functions.
What other good editors would you recommend? I like Dev C++ because it's so "light" and how easy it is to compile and run my code. I've tried Visual Studio but it's a bit of a pain.
Ignoring for a second that your code doesn't even compile, the scope of file in the snippet above is limited to the GetName() function. When you return a pointer to it, you're returning a pointer to memory you have no business accessing any more. Derefrencing that pointer outside of GetName results in undefined behavior. As far as C++ is concerned, your computer could blow up. This is a very bad thing to do.
What's more, your function attempts to do a lot more than the name implies, and returns a pointer to something that doesn't remotely resemble a name. You should name your functions appropriately. Your variable name in function main is obviously not meant to hold a name as it is a two dimensional array. It looks more like it's meant to be the grid the game plays out on. If it is, it should have a name that indicates what it represents.
I hate to present the criticism without also presenting an alternative so maybe the following will get you on the right path:
I've installed the version you mentioned but it has so far been AWFUL. It took about 7 tries to complete the "first time setup" without getting an error. Now, it won't directly open any .cpp file, I have to have Dev C++ open to be able to open any files. It's all been a pain, I think I may just switch back.