1,358 Posted Topics
Re: [QUOTE]sizeof gives you the size of the type at compile-time. In this case the type of buf is a pointer to char which, most likely, has either 4 or 8 bytes. So sizeof(buf) will equal either 4 or 8.[/QUOTE] Not necessarily true. What sizeof() returns for an array is dependant … | |
Re: Here is a [URL="http://www.gidnetwork.com/b-38.html"]properly formatted[/URL] version of your function: [CODE] int factorial(int n) { { if (n == 0) return 1; // Base case else return n * factorial(n - 1); // Recursive case } cout << "returning: "<< n << endl; //THIS WAS ADDED TO GET OUTPUT!!! }[/CODE] As … | |
Re: It is never safe to "AssUMe" anything, you know what that does (and no, I don't expect everyone to get that joke). When your class A is instantiated, it is currently instantiated with a "dangling pointer". It is your responsibility to initialize it to NULL in your constructor. Also, because … | |
Re: I don't know DX, so I can't help with that. I'm sure AD will be along soon with some sort of insight. I know you'll have to detect and respond to OnKeyPress, OnKeyUp, or OnKeyDown type events (actual names are probably different, but you get the idea) and write the … | |
Re: Usually, a seg fault is the result of overruning the boundaries of an array or another similar container. Double-check all your container access statements to make sure your not accessing a subscript that is larger than (container::size - 1). The error is a little difficult to understand, but it seems … | |
Re: [QUOTE=mike_2000_17;1316573]Well, okteta reads binary data and prints it out in hex format (to be more readable than if you opened a binary file in a text editor). So what you need to write is binary data: [CODE] ofstream myfile; myfile.open ("output.midi",ios::binary); char buffer[44] = {0x4D,0x54,0x68,0x64,0x00,0x00,0x00,0x06,0x00,0x01,0x00,0x01,0x00,0x80,0x4D,0x54,0x72,0x6B,0x00,0x00,0x00,0x16,0x80,0x00,0x90,0x3C,0x60,0x81,0x00,0x3E,0x60,0x81,0x00,0x40,0x60,0x81,0x00,0xB0,0x7B,0x00,0x00,0xFF,0x2F,0x00}; myfile.write(buffer,44); myfile.close(); [/CODE][/QUOTE] Won't that … | |
Re: It's because get_tp() returns a copy of tp as a temporary (and most likely const) int. It doesn't return the actual member. | |
Re: [QUOTE="mahsa.ehsani"]i wrote the code of tic tac but it has an error: fatal error C1004: unexpected end-of-file found please help me[/QUOTE] If you want help fixing your code, you have to share your code. Your post gives us absolutely nothing to work with. | |
Re: I'm not versed in the nuances of Linux, but I do know that the integer value zero (0) is not the NULL character. The NULL character is '\0'. I suspect this is part of your problem. | |
Re: That file is a debug database. Normally, other than your finished exe, there really isn't anything mission-critical in that folder (and even the exe really isn't). Try renaming it to "vc90.pdb.old" or moving the file to a different folder then recompiling. I think it will just create a new one … | |
Re: Last couple weeks I've been reading "Beginning C++ Through Game Programming" by Michael Dawson. I was worried that it would be somewhat lame because I've been reading some more-advanced stuff lately, but it's actually been a rather enjoyable read. It covers all your basics (types, control structures, etc.) plus a … | |
Re: [URL="http://www.cplusplus.com/reference/stl/set/"]In order to work properly sets require that you provide a comparison function.[/URL] [URL="http://www.cplusplus.com/doc/tutorial/classes2/"]You will need to write an overload for the less-than operator.[/URL] | |
Re: EDIT, nvm. I need to check something first. | |
Re: As AD had hinted, you seem to be forgetting that array indexes start at zero (0) and end at (size-1) (a.k.a. length-1). Line 23 is using "length" as an index. The element "strng[length]" does not exist, making that an invalid assignment. | |
Re: [URL="http://www.cplusplus.com/doc/tutorial/arrays/"]It is possible as long as your instructor allows it.[/URL] It's a good idea to use a function when you can, but in this case it will only save you 1 loop, 2 if you count the nesting. | |
Re: Actually, this is better: [CODE]#include <iostream> using namespace std; void func(int *const array); int main() { int array[] = {10,20,30,40}; func(array); // func(&(array[0])); // AN ALTERNATIVE MENTHOD OF SENDING cin.get(); return 0; // IT'S GOOD TO SEE BEGINNERS USE int main() INSTEAD } // OF void main(). GJ! void func(int … | |
Re: What do you mean by "without having to pass an int value for it"? Can you give an example of the kind of output you're looking for? There is the macro __LINE__ which gets replaced with the current line number, but it's an integer. | |
Re: [URL="http://www.daniweb.com/forums/thread573.html"]That won't work until you do some work.[/URL] | |
Re: I think it's fairly obvious... You'll need output, input, and comparison statements. Hmmmm...., you'll probably need some loops and a return statement as well. | |
Re: Are you using floats instead of doubles? A float can be thought of as a "single" from other languages. A double is more precise than a float. | |
Re: I think you may want to use an [URL="http://www.cplusplus.com/reference/stl/map/"]STL std::map[/URL], if that's allowed. Read the 6-digit numbers into an integer variable such as an "identifier" variable or something of that nature, then read the value into a "value" variable of some sort. Once the data is read, use the [URL="http://www.cplusplus.com/reference/algorithm/find/"]std::find() … | |
Re: There are macros defined in the standard libraries, they are "EXIT_SUCCESS" and "EXIT_FAILURE". Find those macros and see what their values are. That may help you understand. Sometimes you'll see "return EXIT_SUCCESS;" at the end of a piece of code. This is exactly the same as putting "return 0;" at … | |
Re: [QUOTE=Rez11;1310805]I'm getting weird letters and numbers when the array is being shown. What is the problem? I've initialized array1 with 10,20,...etc. So shouldn't it cout those numbers? [CODE] #include <iostream> using namespace std; void reverseArray(int[], int); int main() {//start main const int size = 5; //constant size of array is … | |
Re: If you have composition, then the this refers to whichever "object" the current function is a member of. [CODE] class A { private: int somePrvInt; public: A() : somePrvInt(0) {} int getPrvInt() { return this->somePrvInt; // this refers to the current A object } }; class B { private: A … | |
Re: It's because you are performing integer division instead of floating point division. Are the only acceptable test scores integers (i.e. 66, 85, 98, etc.)? Or can you get a decimal grade on a test (i.e. 98.6, 82.5, etc...)? It actually makes a big difference here. [URL="http://www.daniweb.com/forums/thread296087.html"]See this thread for more … | |
Re: Code::Blocks is good, but you need the package that comes with the compiler (mingw). Stay away from Dev-C++, it's not very good (at least not in my experience, but I had the Bloodshed version, not the wx version). | |
Re: "well designed software architecture" is both safe and fast. You use const several different ways under different circumstances to produce [B]safer[/B] code. You don't use const to improve software performance/speed, that's what pointers and references are for. The idea of references is a little different. Passing by reference is used … | |
Re: That is "shorthand" for this: [CODE] if (a > 0) a = a; else a = 0; [/CODE] Look up the ternary operator for more info. | |
Re: Line 71 of main.cpp. What is the purpose of that open brace? I suspect it should be a close brace. | |
Re: You are attempting to initialize the value of SOMEVALUE inside the class declaration. You can't do that. You need to declare the static variable inside the definition, then use a "global" initialization statement outside the class definition. In test.hpp: [CODE] //<<snip>> class Test { public: //<<snip>> static const int SOMEVALUE; … | |
Re: I suggest you read up on the [URL="http://www.cplusplus.com/reference/string/string/compare/"]string::compare function[/URL]. It appears that you are interpreting the return value incorrectly. As a result, a valid input is considered invalid and an invalid input is considered valid. | |
Re: I have a suspicion about your issue, but I have a question first. What does the [noparse]cp::cpImageButton::SetMouseClickCallback[/noparse] method do? Does it modify the DisplayObjectContainer object? | |
Re: I'd consider adding another constant for the Rows instead of using a magic number. This will make future modifications to the program easier and is generally considered good practice. As far as assigning your values, I would suggest you base your if statement on the current value of j rather … | |
Re: I have a sneaking suspicion this is getting into explicit template specialization. That's something that I'm afraid I'm not well-versed with yet... It would need to be something to return a null-terminated array of char or an std::string. Inside it you'll have to do some sort of concatenation operation. How … | |
Re: You haven't given a specific Line number for us to look at, but I'm guessing the error points to a line where you use an std::string. You have not included the standard header <string> all of the functions and operators related to the std::string class are defined in that header. … | |
Re: "Is this correct?" Well, since you asked... Where should I start? [QUOTE] Array form an important part of almost all-programming languages. It provides a powerful feature and can be used as such or can be used to form complex data structures like stacks and queues. An array can be defined … | |
Re: OK, that's better. I think you need to take the time to break the problem down into smaller parts. Figure out how to do the first part first: [QUOTE] ... First input an integer N that specifies the length of the sequence that will be generated(including the first two). This … | |
Re: Line 11. Move this declaration elsewhere. This declaration makes the variable j local to the statement block that the for loop executes, which isn't a bad idea, but it doesn't work the way you think. At the end of each iteration of your for loop, the integer variable j is … | |
Re: You need to pay closer attention to your variable names and what you do or don't have in your code. There are multiple issues here. First, in order to do pretty much anything with C++'s std::string type, you need the <string> header. This won't even compile without it because you … | |
Re: Because INCLUDE, VOID, MAIN, etc... mean nothing to the compiler. [URL="http://www.cprogramming.com/tutorial/enum.html"]Consider creating an enum[/URL] of the words you would like to use then set myKeyword::id to the enum type. [CODE] enum bar {THIS, THAT, THE_OTHER_THING}; struct foo { bar item; } foo baz; baz.item = THAT;[/CODE] | |
Re: I see 3 things: [list="1"] [*]Warrior inherits [B]privately[/B] from Adventurer [*]You attempt to invoke an inherited constructor from a derived constructor's body. [*]You are masking class members with local names. [/list] RE #1: Because of the private inheritance, all of the public members of Adventurer are private and any other … | |
Re: When you do your query, do you get back 3 result rows or 9 result rows? If you are getting 9, you should be able to use the value in the "l_type" column to differentiate the rows. Create a for loop that returns the row result if the value of … | |
Re: That's because you modify xTPos and yTPos on each iteration of the trap placement loop(s) and don't store the previously placed locations anywhere. As a result, the last one created is the only one you have a readily-accessible record of. Additionally, the timing of your operations is off. By the … | |
Re: [QUOTE=mike_2000_17;1305231]Ton problème est que lorsque tu fais l'addition de plusieurs chaines de charactères, ses chaines sont converties en "String^" pour être additionner. Une fois additionné, tu as un String et non une chaines de charactère (char[] ou char*), et ils ne sont pas compatible implicitement. Donc, pour régler le problème, … | |
Re: They're out there, you just need to know what to look for. [URL="http://www.daniweb.com/forums/thread303231.html"]Try this one on for size...[/URL] | |
Re: Look up the term "memory leak" that will explain why. C++ doesn't have "garbage collection" like many other languages. That responsibility is left to the programmer. A destructor can be thought of as your garbage bin. They are used mostly for de-allocating dynamically-allocated components of custom object classes. [CODE]class nonDynamicExample … | |
Re: Of course it is. How else will you figure out how the code works? Just make sure you take the time to figure out what the code you're looking at is doing rather than just copying it verbatim. If you take the time to review the example(s) properly, you will … | |
Re: The first version works because they are not #included to each other. As a result, the class definitions are not visible outside their own files/modules. If you add #include "NewFile.cpp" to the top of your "test.cpp" file, you will get compile errors concerning class redefinition. This applies to variable names … | |
Re: Agreed, you have a dangling newline because of the numeric input. Add an ignore statement to extract it. | |
Re: I don't know how to do it, but you may want to check your terminology. What you are referring to are "resizable" (not scrollable) columns as in an Excel spreadsheet. I would check the class(es) used for the columns to see if there is a resizable (or other similarly named) … |
The End.