- Strength to Increase Rep
- +5
- Strength to Decrease Rep
- -1
- Upvotes Received
- 16
- Posts with Upvotes
- 11
- Upvoting Members
- 11
- Downvotes Received
- 0
- Posts with Downvotes
- 0
- Downvoting Members
- 0
Re: Just extract the bytes from the string and then append the file contents. One way to do that is to create another vector and copy the header and contents there: [CODE]#include <cstdio> #include <cstdlib> #include <string> #include <vector> #include <algorithm> #include <iostream> #include <iomanip> void HexDump( char ch ) { … | |
Re: [QUOTE=firstPerson;1353174]Ok and the code OP showed should be similarly proved right? Like so : Summation from i = 1 to N Summation from j = x, where x = 2^i Thus N * Summation from j = x, where x = 2^i = {1,2,4,8,16...} If you look on [URL="http://en.wikipedia.org/wiki/Summation"]wiki_summation[/URL]. In … | |
Re: The User-agent field is mainly used for formatting the response accordingly (e.g. for mobile phones) and shouldn't result in an error code(4xx). The 405 you're getting means that the method used in the request (POST) is not allowed. If you examine the headers of the response from google.com you'll see … | |
Re: You can use [iCODE]BinaryFormatter[/iCODE]'s [iCODE]Serialize[/iCODE] and [iCODE]Deserialize[/iCODE] methods instead of [iCODE]StreamWriter[/iCODE]/[iCODE]StreamReader[/iCODE]. Here's a little sample I wrote (with no error checking at all): Receiver [CODE]static void Main(string[] args) { TcpListener listener = new TcpListener(IPAddress.Any, 5005); listener.Start(); Console.WriteLine("Server started."); Socket client = listener.AcceptSocket(); Console.WriteLine("Accepted client {0}.\n", client.RemoteEndPoint); List<string> l = null; … | |
Re: I didn't test it, but here are the problems I saw: First, your bounds check is incorrect - [iCODE]if((row == size) || (row < 0) || (column > size) || (column < 0))[/iCODE] should be [iCODE]if((row >= size) || (row < 0) || (column >= size) || (column < 0))[/iCODE] … | |
Re: [QUOTE=daviddoria;1346490]I see... why do they provide these make_heap functions then?[/QUOTE] Because you might have an existing collection that you want to turn into a heap in-place, instead of duplicating the elements using [iCODE]push[/iCODE]es into a [iCODE]priority_queue[/iCODE]. Or, if you want to guarantee a O(nlogn) bound of a sort, you can … | |
Re: There's a newline between 1010101a and 1a, which has a different character code from 'a', so you get an additional [iCODE]true[/iCODE] in your vector. | |
Re: Use [iCODE]_tprintf( TEXT("%s"), lpszDevName );[/iCODE] instead. You'll also have to [iCODE]#include <tchar.h>[/iCODE]. | |
Re: Here's some code that issues a GET request and writes the response to file. I tested it on Windows only, but it should work on Linux, too. It doesn't exactly "fill the search box, and click submit button", but should be enough to get you started. [code] #ifdef WIN32 #define … | |
Re: The problem lies in the loop filling the bitmap data. You can make a simple calculation of how many bytes you are writing - 3 each iteration, width*height/3 iterations - a total of width*height bytes, not pixels. Essentially, you're writing to every third pixel, hence the diagonal lines. To correct … | |
Re: This code should only hang if you lift the key while the worker thread is executing this: [code] while(WaitForSingleObject(input->run, 0) != WAIT_OBJECT_0) { SetWindowTextA(input->hWnd, "Hello"); Sleep(500); SetWindowTextA(input->hWnd, "Goodbye"); [/code] but not this: [code] Sleep(500); } [/code] The problem is that [iCODE]SetWindowText[/iCODE] actually sends WM_SETTEXT (sends, not posts) so it blocks … | |
Re: You can do fine using the STL's priority queue with some modification of that pseudocode - namely always inserting the neighbours in the PQ, unless they are in the closed set. This will result in having duplicate nodes (with different f/g costs) in the PQ, so each time you pop … | |
Re: You can use this (and probably add some error checking): [CODE] // Gets the local IP address // IPv4 address and little-endian machine are assumed #include <cstdio> #include <ws2tcpip.h> #pragma comment(lib, "ws2_32.lib") int main() { WSADATA wsadata; WSAStartup( MAKEWORD(2, 2), &wsadata ); char buffer[256]; struct addrinfo * result; struct addrinfo … | |
Re: You are taking the address of a [iCODE]char[/iCODE] pointer to get string and taking the address of a [iCODE]char[/iCODE] to get the character itself - these are the problems with [icode]cout << "Characters:" << &temp << endl[/icode] and [ICODE]while(&temp[i]!=0)[/ICODE]; In the former, you're taking the address of the pointer [iCODE]temp[/iCODE], … | |
Re: As firstPerson said, the last digits can be obtained by modular exponentiation. Getting the first digits requires some mathematical trickery, but nothing too special. I've commented the code so it shouldn't be hard to understand. [CODE]#include <cstdio> #include <cmath> typedef unsigned int UINT; typedef unsigned long long ULL; //-------------------------------------------------------------------------------------- // … | |
Re: You're probably missing [I]comdlg32.lib[/I] in your linker settings. By the way, the Common File Dialog API has been superseded by the [URL="http://msdn.microsoft.com/en-us/library/bb776913(VS.85).aspx"]Common Item Dialog API[/URL]. | |
Re: You have to process the WM_CTLCOLORSTATIC message in the parent window (WM_CTLCOLOREDIT should you change the edit box style so it is neither disabled nor read-only). It is sent by the control to its parent before being drawn, passing its device context in the WPARAM, so you can change text/background … | |
Re: It's always nice to see people posting tutorials, but I have to disagree with both pieces you posted. You need not do any of these things, because that's the compiler's job - making the machine code optimal. Precalculating constants and rearranging expressions in weird ways only makes code hard to … | |
Re: HTTP headers must end with a CR/LF line, so you should add [ICODE]sprintf(Get_Request, "%s\r\n", Get_Request);[/ICODE] at the end to get it working. Also, when [ICODE]recv()[/ICODE]-ing, you shouldn't use [ICODE]strlen(Response)[/ICODE] as the length argument, since your buffer isn't initialized, so [ICODE]strlen[/ICODE] will pretty much return random numbers. Instead, use [ICODE]sizeof(Response) - … | |
Re: You can call [ICODE]ISpVoice::Speak[/ICODE] asynchronously and then use the [ICODE]ISpVoice::WaitUntilDone[/ICODE] method, which does exactly what you want. [CODE]pVoice->Speak( szText, SPF_ASYNC, NULL ); pVoice->WaitUntilDone( 3000 ); // 3 seconds[/CODE] | |
Re: The problem lies here [icode]HashTable = new (nothrow) ListSet [size];[/icode]. [i]Short explanation:[/i] You are allocating an array of [icode]ListSet[/icode] [b]objects[/b] and handing the returned pointer to a [icode]Set *[/icode]. This is not how inheritance works - you should allocate an array of [icode]Set[/icode] [b]pointers[/b] instead, and then allocate a [icode]ListSet[/icode] … | |
Re: Assuming 2^n takes O(1) time, the complexity is O(log* n), that is, the [URL="http://en.wikipedia.org/wiki/Iterated_logarithm"]iterated logarithm of n[/URL]. | |
Re: You can use one of the [ICODE]Marshal::StringToHGlobalAnsi/Auto/Uni[/ICODE] methods to copy the string into unmanaged memory, and then clean up with[ICODE] Marshal::FreeHGlobal[/ICODE] when you're done. There's an example [URL="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.stringtohglobalansi.aspx"]here[/URL] that does exactly that. | |
Re: This happens because [icode]StreamReader::ReadLine[/icode] returns [icode]nullptr[/icode] when the end of stream is reached (which is the case when reading an empty file). That means that on line 8 of your code [icode]line[/icode] is now [icode]nullptr[/icode], and not the initial empty string. Since they do not compare equal to each other, … | |
Re: The [icode]recv()[/icode] function will return <= 0 if either a socket error occurs or the socket has been closed on the server side. If none of these are true, it will just block, waiting for data. So, I'm guessing your problem is that you didn't close the socket. If, for … | |
Re: What is the desired direction of the ray? If it is +Z, just specify (0,0,1) for rayDirection. Currently you're generating something rather strange - a direction parallel to the line, defined by the points (0,0,0) and (shotOrigin._41, 0, shotOrigin._43) from line 4 of your code. Otherwise, the conversion from world … | |
Re: There are quite a few things wrong :). - All the "mdim_ = mdim_;" stuff is useless. - In the Matrix(int cols) constructor, mdim_ remains uninitialized and you're getting a crash - you should set it to cols. - The SetElement() function is incorrect, it should read: [code=c++]void Matrix::SetElement(int m, … |