Okay, third fourth try at writing this code:
/*
Showing the applyText function here for reference:
Okay, third fourth try at writing this code:
/*
Showing the applyText function here for reference:
Why are you wasting 1/3 of most lines with spaces so you have to sidescroll all the time?
Also there are so many magic numbers in there where one cannot know what those are.
I would also put some smaller parts of it into their own functions and use a switch statement.
Why are you wasting 1/3 of most lines with spaces so you have to sidescroll all the time?Also there are so many magic numbers in there where one cannot know what those are.
I would also put some smaller parts of it into their own functions and use a switch statement.
Well, the indents are because it's already inside a bunch of if and while statements, as it's just a small segment of the much larger program.
I'm not quite sure what you mean by magic numbers, but most of the variables are probably not relavant.
Can you comment this like just a little so we can follow the logic please thank you.
Sure.
Magic numbers like those 20, 100, 1000, 999999 you repeatedly use, I would put into constants with an informative name thats defined only once to prevent errors and aid in understanding the program.
If thats a function that is even longer than shown and needs that much indentation its a sure sign its too huge, which makes it difficult to debug.
From reading your code I even get doubts if that is just C and not C++. So if this is C++, how about programming a class first that implements all logic to the console and then some other class to place, align and draw everything in a window on your screen that can be used from your main loop? And if its really C, why not use some similarly split up functions in separate files?
Just because it's c++ doesn't mean I'm using a console? What on earth would make you think that?
And who said it's C?
And no, it's not a function, it's inside an if statement inside an events loop inside the main function.
[quote name='Syerjchep' timestamp='1357767598' post='5019637']
Just because it's c++ doesn't mean I'm using a console? What on earth would make you think that?
And who said it's C?
[/quote]
console as in "that thing people build in their graphics mode game for typing in text" not console as in "guy makes text mode game that runs inside a shell window".
And noone said its C, but you are just using C constructs like C array, C style struct access, C style number twiddling loops, ...; theres nothing really looking C++ like using STL, method calls,...
[quote name='Syerjchep' timestamp='1357767598' post='5019637']
And no, it's not a function, it's inside an if statement inside an events loop inside the main function.
[/quote]
I know and thats whats wrong with it.
Updated the origional post.
Even though I haven't even finished rewriting what I had before (you can't actually edit the text yet), it still seems to crash it.
Why are you using a 'character grid' instead of an std::list<std::string>? You could check each string and split it when you encounter a newline, pushing back multiple substrings to the list, and popping the front of the list when you get beyond your desired buffer size (say, 100 lines or more).
Which function is crashing? Under what conditions does it crash?
Are you saying the program crashes before you even enter int main()? If so, it's probably because your "char charactergrid[1000][1000];" takes up almost a full megabyte on the stack. You shouldn't put that kind of memory on the stack, it's not made for that. Using a std::vector (not 2D!) or std::list of std::strings is a far superior and 'correct' solution.