278 Posted Topics
Re: It depends on the instruction, there are shortcuts for longer commands, which in assembly are 2 or 3 'words' but in binary are just 1 opcode. As an example: xor eax,eax Is smaller than mov eax, 0 Also, take a relative jump for example - it's 5 bytes, but a … | |
Re: [QUOTE]The result doesn´t need to be a number with a decimal.[/QUOTE] How do you know? 0_o Anyway, we need more info: How is this function called? (e.g. how are arrayStart and arrayEnd initialized). Could it be a problem of an edge case? [code=cpp] for (tempPtr = arrayStart; tempPtr != arrayEnd+1; … | |
Re: It will be a dangling pointer, so just be allocated for nothing. Because you overwrote ptr, you can't call delete[] anymore on the original ptr. | |
Re: You mean what value m_item will hold? That depends on the type of DataType. It's default constructor will be called, without any parameters. If DataType is an int, it will behave just like 'int m_item;' would. Not sure if this is exactly your question though (just had an exam from … | |
Re: >> is simply a function call, which can fail. So check if the cin >> userGuess succeeded or not: [code] if( ! (cin >> userGuess) ) // not an integer, do something [/code] (the () around cin >> userGuess are important.) | |
Re: Google for 'cin' and C++. Also, you're now using the C function for output (printf), in C++ we generally use 'cout'. | |
Re: What do you want to achieve with this: [code=cpp] B () : x(y) { B <t-1> (); // What do you think happens on this line? } [/code] The design currently makes very little sense. Does the assignment specifically state 'array', if so then you probably are not allowed to … | |
Re: In C++ NULL is defined as 0, so it won't make a difference. (The use of NULL is even discouraged by some, including Stroustrup). | |
Re: Consider this: [code=cpp] HANDLE fHandle; for( int i = 0; i < 7; ++i ) { fHandle = CreateFile( ... ); } close( fHandle ); [/code] First time CreateFile is called, let's assume that fHandle will be set to 0x00000001. The next time it's set to 0x00000002, until 0x0000007. After … | |
Re: That's not an easy thing to do. Do you have any other information what this function supposedly does? Does it show a message box? Does it print something? Does it write a file? etc. | |
Re: There are several ways, look at std::sort: [url]http://www.cplusplus.com/reference/algorithm/sort/[/url] By default it uses the operator<, so you can create a class that inherits from vector and overload the operator<. Or, more easily create a 'compare' function and hand it over to sort. After you've sorted the vectors, you can iterate through … | |
Re: You run the program, select the option that will read the file, then the program closes and you re-open. You then select the option that will print the data that was previously read? That won't work. In the first instance, the data is read into memory. All of that memory … | |
Re: compile with symbols, execute `ulimit -c 1024` (will create a core dump when your program segfaults), then use gdb on the core dump, and tell it where your source files are so that it can tell you where the error originates. How can you manage a 14k line program without … | |
Re: A templated function doesn't _need_ to be defined in the header file, however it is usually easier to do so (see [url]http://stackoverflow.com/questions/115703/storing-c-template-function-definitions-in-a-cpp-file[/url] ). Inline functions however need to be in the header file, this has to do with 'translation units'. If you have an inline declaration in 'inline.h' and it's … | |
Re: Run your code under a debugger (You use Visual Studio after all) to get more detailed information about the crash. The pasted code is too long to read through when the range can be narrowed down very easily ;) | |
Re: You're not actually modifying the inTables[q].Items in your first loop. [code=cpp] for each (AoE2Wide::DrsItem item in inTables[q].Items) { // item is a copy of what's at inTables[q].Items, modifying item will leave the item in inTables[q].Items in tact } [/code] | |
Re: I dont think you fully understand what templates are for, let's look at the name setter for example: [code] template <typename N> N setName(N n) { Name = n; return n; } [/code] Why do you need a template function here? Name is always a string. So this would do … | |
Re: Do you know what a class is? Have you learned anything about object oriented programming? | |
Re: First post I thought I spotted an error in pQuery, since this is rather weird: [code] sprintf(buf,""); int ret = vsprintf(buf + strlen(buf) [/code] the strlen put me off. The real error is that you can't compare a char array with ==, there are functions to do this (e.g. strcmp, … | |
Re: In write_it (I guess that is where it crashes?), check what the value of 'buf' is, is it a valid pointer? I don't know how this 'curl' library works though, so just guessing here | |
Re: You're not receiving anything, it prints uninitialized data. You set the socket to 'nonblocking' and then continuously call recv. So even if there is no data coming from there server, recv will return. You do not check the return value of recv before printing it, the return value is probably … | |
Re: [url]http://www.cplusplus.com/reference/iostream/manipulators/setprecision/[/url] | |
Re: For one, MD5 shouldn't be used any more. And it's going to be fairly trivial to bypass this. A reverser can just put a breakpoint on when your program attempts to open a file.. this is going to be somewhere at the beginning of the 'check license file' function. He … | |
Re: [QUOTE]tei.h:56:10: warning: multi-character character constant[/QUOTE] 'T0' is not a character, it's two characters. [QUOTE]tei.h:7: error: aggregate ‘foititis p’ has incomplete type and cannot be defined[/QUOTE] Where is 'foititis' declared? Is this declaration available in tei.h ? | |
Re: What happens here: [code=cpp] char* a = "Hello world"; cout << a; [/code] a is a char*, so cout starts printing until it finds a null character. It prints Hello World. [code=cpp] char a = 'p'; cout << &a; [/code] a is a char, but &a is also a char* … ![]() | |
Re: You can't execute another query, without freeing the last result. So you need to do one query, use the results, free the results, do the next query etc. | |
Re: There are many ways to do this.. Why do you ask if your solution is correct? You can check it for yourself by printing the first 11 values of f, to see if they match a. Your declaration of 'main' is bad.. I hope the teacher did not show you … | |
Re: [quote]Basically I want to be able to implement the C# code that occurs into C++ code instead.[/quote] Your question is a bit vague... Do you want to execute C++ code from this C# program so that you can replace it 'in small parts'? If yes... don't even try. What I … | |
Re: No, notice the & sign before tc_a? This means tc_a is a reference. So tc_a will reference p, which essentially makes them one and the same object. Have you ever used references in function parameters? If not.. this is a good time to read about it ;) | |
I'm designing an exception class, but ran into a case where a copy is being made which I don't want (plus, I don't understand why). Consider the following cases: [code=cpp] // 1 Exception e; throw e; // Copy: yes //2 throw Exception(); // Copy: no //3 throw Exception() << "extra … | |
Re: Think about what you're doing. You want to start j at i + 1, is there any orther variable that you could use for this, that IS defined at for( int j=... ) ? If you declare a variable inside the for statement like this, it is ONLY visible inside … | |
Re: There are several ways... Create a file on startup, and remove it again on exit. If on startup the file already exists, then refuse to start. Or.. a better way: Create a mutex in the global namespace(CreateMutex @msdn) on startup and destroy it on exit. If the creation fails with … | |
Re: How can we help you if we don't know what your program needs the access for... And how do you know it's not working - is there are an error code like that says access is denied? | |
Re: Tell us what you need to do please, without knowing some more details it's hard to suggest something. | |
Re: You are printing everything... in the while( ! eof ) there should be an if before the cout. You have 1 'code' variable, that you both use for the input from the user (cin >> code) and when reading from the file(getline(..,code,..)). You need two variables.. one for the user … | |
![]() | Re: Depends on the type you're reading.. If you store the user input as string, you can access the individual numbers(characters) just like you would with an array: [code=cpp] string test = "12345"; test[0]; // '1' test[4]; // '5' [/code] ![]() |
Re: Better show us the code.. You probably have the implementation of this class in two .cpp files | |
Re: When someone is 'tenured' it means that they can not be fired without a 'good reason'. In C++, a 'Boolean' is 'bool'. So you can just give the class a member 'bool m_tenured;' | |
Re: It goes wrong in free. sizeof( mem ) will be the size of a void*, not the size that was previously requested in Alloc. Also.. be careful with pointer arithmetic: [code=cpp] char* pChar = 0; pChar++; // pChar will be 1 int* pInt = 0; pInt++; // pInt will be … | |
Re: [code=cpp] while (start == 1) cout << "\n"; [/code] Those two lines will be executed forever, you need to indicate all the code that belongs inside the while loop by putting it in { }'s | |
Re: [code=cpp] if(nextLetter==phrase[i]); [/code] There is a ; after the if, so letterFound will _always_ be set to true. Edit: Also, I think it would be cleaner to use for loops instead of while... the use of while is confusing in this case, and it is very easy to forget the … | |
Re: Look at QT, it is a cross platform UI 'framework' | |
Re: When you add a Looper, it is 'sliced' to it's base class. What you need to do is store pointers or references to AudioTrackElement, they will 'preserve' the class hierarchy. So: [code=cpp] AudioTrackElement* pNewEl = new Looper(); pNewEl->process( ... ); // calls Looper::process delete pNewEl; Looper newLoop; AudioTrackElement newEl = … | |
Re: sizeof is a compile-time 'function'... it cannot get the size of dynamic arrays. So, your code is very wrong... your intention is to write 3 items into a, but there is only space for 0 items. | |
Re: You are calling a function 'isEmpty()'. That does not exist anywhere, does it? If you want to check if a stack is empty, you can call 'empty()' on the stack. So: [code=cpp] while( !myStack.empty() ) [/code] | |
Re: I have use Code::Blocks for a long time (code completion was close to absent in the old version, but improved greatly in the latest. If you stick to nightly builds it's even better). I still use C::B if I have to develop on Linux, but for Windows I switched to … | |
Re: Interesting... Haven't thought about this much, but I guess a relatively straight forward method is to store the sClient on the heap, hand a pointer to it over to the thread.. and then copy it to the thread's local storage, finally free the memory you allocated on the heap in … | |
Re: This will work, because the hard coded strings are stored in the strings section of your executable, and s just points to that. After the function returns the string will still be there. static storage is if you declare a variable like this: [code=cpp] void myFunction() { static int myStatic … | |
Re: Here on Daniweb you won't get much help without showing some effort of yourself. What have you done yourself? Have you ever programmed in C++ before? If not, start doing (hands-on) tutorials. | |
Re: The front/rear is a little confusing. If I push two items, rear will increase by 2. front remains unchanged, but in holds() you output front. So, that explains why holds() gives the wrong size? |
The End.