#
students = malloc(sizeof(struct student));
#
strcpy(students[0]->name, "jack");
I might have missed it, but of what type is "students"? It seems to be an int, since the declaration is lacking a type.
#
students = malloc(sizeof(struct student));
#
strcpy(students[0]->name, "jack");
I might have missed it, but of what type is "students"? It seems to be an int, since the declaration is lacking a type.
Regression? Don't you mean iteration? Could be wrong, but according to wiki (I had to look it up) regression is bug-related, not loop related like recursion.
If you mean iteration, then that is faster. But, recursion could give you a lot cleaner code, so it's basically okay to write big functions recursive, large functions iterative.
Define "doing the same thing".
I can drive to the store on my bike and in my car, doing 2 different things. Or I can say that I'm going to the store, doing one thing, in 2 ways.
C compilers will probably never output exactly the same output as when you would hand-code it.
It's called a
bool
in C++ ;)
You can create types with typedef.
typedef <newtype> <oldtype>
IIRC
You can have a monster class with a function isHit(const unsigned int x, const unsigned int y); that returns whether the monster is hit. This makes the hit function belonging to the player really short, since it only needs to feed 3 coordinates, the monster does the rest. Like this, you can hide big pieces of code, make sure they work and never look at them again until you want to change them.
Best of luck with it, I might also take a look at it myself if you like? I'm kinda out of projects now, and this seems a nice project with a dedicated developer. Besides, I have some OpenGL skills if you'd like it to be more visual...
Let me know,
You're coding in C++. Forget about global variables, try and make a class that has all those variables. If you can't fit it in a class or function you're quite possibly doing something wrong. Globals are considered dangerous when you tend to use them as much as you do. It also cleans up your code a lot, 2000 lines is a lot, especially when I think you could make it a lot more readable by splitting all the code up in classes. Having the functions that need the member variables of a class in that same class or friends of that class also eliminates the need to pass every variable and allows you to simply make private "safe" data members.
2, 3, 4 should be solved by learning and using classes. 1 is very advanced and will make your eyes bleed and your program deadlock. ;-) Assigning each monster its own thread would do you little good since you'd have to lock every variable/array it'll access and unlock it... It will probably slow down the program quite a lot.
Well, really try to encapsulate most of the functions and variables into classes. That should be your focus. I like the idea and your work on the RPG though! Very cool. :D
The monster hit algorithm could be something like this right:?
For each monster
for each hit coordinate
check if the monster.location == hitcoordinate[n]
if so do damagerollorsomething
I said
int main
not
int _tmain
EDIT: That might sound a bit harsh. No hard feelings, it's just what I said.
Erm..you're using MSVC++ right? What I posted before should work... You might want to get GCC for Windows tho. It doesn't rape the standard as much.
Oh, and post your code again please. Like it is now. May seem tedious, but it gives valuable information.
Just make it
int main(int argc, char *argv[]){
It also works on MSVC++.
@ iamthwee: Examples on MSDN use that, I think.
Can't you use qsort() for this? It'd make the code a lot shorter... and easier I guess.
And a, a bit more precise about the error? What are you getting? Segfaults or just a not-sorted listbox?
First: read the link william posted. It's important.
And...
I've said some more, also answer those questions. It doesn't make sense you're using a <char*> when you've included <string> for example.
EDIT:
cin >> <char*> should work, but be sure to first make the <char*> point to some allocated memory with the new operator. And keep in mind that it won't parse spaces.
To parse spaces as well, use cin.getline();
Your output mechanism should work, but you might want to get rid of ios::app, just try it with ios::binary alone.
What errors are you getting?
Why isn't your code in code-tags?
... or indented for that matter?
You should post this along with your compiler.
You're trying to use cout without #including <iostream>
. That won't work I guess.
You're #including <string>
, but then using a <char*>
instead of a <string>
!
On top of that, you're declaring a pointer that's pointing to ANY place in the memory and ordering cin to write the input to that? I think that's what you were trying to do.
I don't know how cin and char*
work together, but it's better to make per a <string>
instead of a <char*>
, so you won't run into memory troubles.
I just meant to say he's trying to create a C program I guess, using a C++ compiler since only a C++ compiler will throw that error. Nothing more.
"cannot convert from" is a C++ (and in general, OOP) only error afaik.
You're getting C++ errors. C++ is a lot stricter. Try using a C compiler. ;)
Shouldn't matter in what language your DLL is made, I think you need to figure out how to thread in RealBasic and call the functions from your realbasic program.
WndProc is a callback function. I don't call it.
So, declare a static struct in WndProc and pass a pointer... That makes sense. Thanks.
I'm writing this windows app and I can't figure out how to let the user manipulate data (in a function called by WndProc) without using globals. Do you think it's better to use one global array/struct than lots of tiny globals? That'd make sense.
Well, I tend to use them when it saves me adding numerous parameters to some functions. I think you can use global variables, but you should at least limit most of them to one source file with the static modifier (or without, since it's the default). When you write a throw away program, it's okay to use them, but globals aren't built to last.
Just open it for reading and writing. Write to it, read from it.
What's the problem? You can find how fopen works for reading and writing on numerous C reference sites.
Open it for reading and writing?