825 Posted Topics
Re: If you are going to binary search a file you need to do one of two things. A) Store all entries as fixed-width (That way you can calculate jump offsets precisely) B) Use the current file position to jump to a new location (based on file size) and search for … | |
Re: You could always take advantage of the short-circuit operators.[code] switch (argc) { case 1: { printf("1\n"); break; } case 2: { printf("2\n"); break; } case 3: { printf("3\n"); break; } case 4: { (f) && printf("4\n"); break; } case 5: { (f) && printf("5\n"); break; } case 6: { (f) … | |
Re: You could look at [url=http://www.antigrain.com/]agg[/url]. There are several examples on the site that show how easy it is to plug the components together. Basically, it's just a bunch of facilities for plugging together behavior in a pipeline. The facilities themselves, however, are fairly simple. | |
Re: Try casting the address of i instead of the value. For instance[icode](void *) &i[/icode] casts the address of i, [icode](void *) i[/icode] casts the value. In the latter case you would be trying to read the value at location 0x0, 0x1 and 0x2. In addition, when you assign in your … | |
Re: A network router is a serious undertaking. Especially if you intend to handle all the details of what a router [i]really[/i] does and not just implement a static lookup table. I'd suggest that you start to look at things already designed for this purpose. One that I am familiar with … | |
Re: I'm not sure what you mean by a "C++" console. However, if you mean what you see in the console after running your program then it depends on your system. If you have access to the source code of the program then you can replace all the output streams ([icode]cout[/icode] … | |
Re: How about creating an array of pointers to functions that will modify the contents of a file in some way. If each function writes one word you could write a sentence to file by way of iterating over an array of function pointers. This really depends on your ability level. … | |
Re: Threads are particularly tricky for people who have not programmed them before. If all you want is blocking behavior just encode it in your design. FOr instance[code]int MoveToHQ () { ... } EmptyVehicle () { ... } GoToResource () { ... } StartCollecting () { ... }[/code]Then, in the driver … | |
Re: If you are certain that you will only be getting numbers you can read a single character at a time, convert it to an integer value, then append it to a [icode]std::vector< int >[/icode]. The [icode]vector[/icode] is a dynamic container that will grow to suit your needs. If you [i]must[/i] … | |
Re: While there are iterative approaches to this type of problem, the solutions lend themselves to recursion. Consider the following pseudocode [code]fun show_stars (current, increment, max) return if (current > max) print_spaces (max - current) print_stars (current) show_stars (current + incrememt, increment, max) # Recursive call print_spaces (max - current) print_stars … | |
Re: First, I assume that you mean palindrome, not anagram? A suggestion, use [icode]std::string[/icode] since you [icode]#include <string>[/icode], it will make your life easier. Especially since if you [icode]#include <algorithm>[/icode] there is the option to use [icode]std::reverse[/icode]. There are other things about your code that are curious, too. Using an int … | |
Re: [QUOTE=Zjarek;1504609]There is [URL="http://www.cplusplus.com/reference/algorithm/for_each/"]for_each[/URL] in c++, but I think this is not what you mean...[/QUOTE] What give you that indication? The [icode]std::for_each[/icode] is the generic way to iterate over a sequence. Types need not be provided as they are encoded in what you are iterating over. | |
Re: Wanting a string is easy, even if there are digits in it :) A user entering nothing is even easier as your program will not get any input. To verify a particular input you can set exceptions to be thrown when things go awry or take everything as a string … | |
Re: What have you tried so far? Help is not free - especially the kind of help you are asking for. | |
Re: The conversion can be tricky (does your csv allow quoted commas?) but you could just translate all ',' to ' ' and parse using a stringstream. For example:[code]#include <iostream> #include <string> #include <vector> #include <sstream> int main () { std::string s = "123.45,213.76,234.16"; std::size_t pos = 0; std::vector< double > … | |
Re: Did you try Narue's suggestion? | |
![]() | Re: There is very little context with which to answer this question. [i]Where[/i] does valgrind say the leak is? Your code, within the ncurses library? Do you just get a certain amount of increase in memory size, and not necessarily leakage, per se? Do you call [icode]endwin()[/icode]? Does the leak exists … ![]() |
Re: For static analysis, there is another tool that is very powerful: [url=http://www.splint.org/]splint[/url] | |
Re: [code]int matrix_ops(matrix * m1, matrix * m2, matrix * sum, matrix * pdt)[/code] Where [icode]sum[/icode] and [icode]pdt[/icode] are empty matrices to be filled in within the function. | |
Re: You can do one of two things to avoid the name clash: 1) Remove the [icode]using namespace std;[/icode] 2) Use [icode]::max[/icode] to indicate the locally scoped version of the function This is one of the caveats of that [icode]using namespace std[/icode] approach. | |
Re: You can use [icode]std::stringstream[/icode]. For example:[code]#include <string> #include <sstream> #include <iostream> int main () { std::string s = "12345"; std::stringstream ss(s); int value = 0; std::cout << "value before: " << value << std::endl; ss >> value; std::cout << "value after : " << value << std::endl; return 0; }[/code] … | |
Re: [quote] Naturally SomeValue will never be bigger than the array size.[/quote]Many a program have been buried for just that belief. Check that value. In addition, it might be enlightening to see your URLDownloadToFileA implementation to ensure that the problem isn't within that method. | |
Re: My preference is to include header files where they are needed. If you need to functionality of [icode]stdio.h[/icode] in your header (i.e you need to use [icode]FILE[/icode]) the include it otherwise it is just noise. | |
![]() | Re: [icode]while(1);[/icode] Drop the semicolon. ([icode]while(1)[/icode]) ![]() |
Re: I'm curious why you do not use [icode]std::list[/icode]. My only guess is that this must be a homework requirement. If you were using a [icode]std::list[/icode] you could just insert and then sort. Given that, you might want to try to write an insert function that adds a single item to … | |
Re: Couple of things. 1) [icode]k[/icode] is not defined anywhere. 2) The do/while construct looks like [icode]do { } while (condition);[/icode] So you may want to make the following change: [code]num = num % fact; while (fact > 1); } cout << "\t\t\t\t" << k;[/code]to[code]num = num % fact; } while … | |
Re: You can have either the php script execute a popen and read from the spawned process or have your C++ program spawn the PHP script and write to its standard input (or use any other formal IPC method). As far as setting environment variables (such as $_GET, $_POST and the … | |
Re: [QUOTE=template<>;1491341][CODE] const char DELIMITER(' '); [/CODE][/QUOTE] There is no need to provide a delimiter of whitespace explicitly. Standard streams (std::cin, std::stringstream) parse on whitespace by default. For example:[code]#include <iostream> #include <sstream> #include <string> int main () { std::stringstream expr("3 + 4 * ( 5 * 8 )"); std::string token; while … | |
Re: The format of an [icode]#ifndef[/icode] is[code]#ifndef XXX // Statements, possibly other pre-processor directives, to happen // when XXX is not defined #endif /* XXX */[/code] So to solve your problem, just add an [icode]#endif[/icode] at the end of your header file. | |
Re: Namespaces are a clarification and encapsulation thing. If you want to associate a section of code with a tag, you can do so with a namespace. For instance[code]namespace foo { class Foo { }; }[/code]Now, [icode]Foo[/icode] belongs to the [icode]foo[/icode] namespace. In order to use a [icode]Foo[/icode] object in your … | |
Re: [QUOTE=lochnessmonster;1485649] if i don't pass a value to my variables in an initialization list, do they automatically get initialized to 0?[/QUOTE] What happens is that the default constructor for the object is invoked (which in this case happens to be 0). Try doing it with an object that doesnt have … | |
Re: I'm not understanding why you are including a crc check here. It seems to me (from the description) that if you have the following [code] A[ 1, 2, 3, 4, 5, 6, 7 ] B[ 4, 2, 1, 5, 4, 6, 2 ][/code] Then your final array should be[code] C[ … | |
Re: Outside of changing [icode]array[index][/icode] to [icode]*(array + index)[/icode] everywhere I'm not sure I understand what you need to do... | |
Re: The class declaration [i][b]is[/b][/i] the prototype of the member function (with optional definition). | |
Re: Google for Beej's Network Programming Guide. It has a decent review of the subject with plenty of examples. [url=http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html]Beej's Site[/url] | |
Re: Is there a reason you dont want to call the methods directly? If you need to provide the type of method to call it's not as if you need additional context to figure it out. Just call [icode]MyClass::SumProductMessageUpdate ()[/icode] instead of delegating. | |
Re: You are perpetually increasing the size of the string (and number of %'s in it). FOr instance:[code]original: "% % %" find("%") -> 0 replace("%%") -> "%% % %" find("%") -> 0 replace("%%") -> "%%% % %" find("%") -> 0 replace("%%") -> "%%%% % %"[/code]And so on. My suggestion would be … | |
Re: Have you tried typing in multiple versions and trying to compile them? That would be the most direct way to figure out what you can and can not do... | |
Re: valgrind is an invaluable tool (if you are on a linux platform). I have not investigated this output, but running your program through valgrind produces [code]==12171== Invalid read of size 8 ==12171== at 0x804858E: bark_edge (t.c:50) ==12171== by 0x8048418: main (t.c:13) ==12171== Address 0x4024028 is 0 bytes after a block … | |
Re: [url=http://linux.die.net/man/3/strtold]strtold[/url] | |
Re: Are you looking for help... or is this just a post showing some work that you've done? | |
Re: You can always use the [icode]/proc[/icode] filesystem which includes entries for all currently running processes. | |
Re: Normally, you would do this with a string stream (or the input stream if you like). For instance, getline will take a delimiter:[code] std::cout << "First names: "; std::string token; getline ( std::cin, token, ',' ); std::cout << "Read token: " << token << std::endl; getline ( std::cin, token, ',' … | |
Re: If you program to an interface it is important to keep with the requirements of that interface. typedefs can help hide information. For instance, suppose that DWORD is [icode]typedef int DWORD[/icode] and you programmed functions knowing that[code]int foo (int param1, int param2); // instead of DWORD foo (DWORD param1, DWORD … | |
Re: The real answer is: it depends. A std::map is implemented as a red/black tree so it is logarithmic in its search (plus whatever operator< imposes). A vector has contiguous memory so indexing is very fast but insertions/deletions from the middle of the vector are expensive. A list has basically the … | |
Re: If you want to catch a signal delivered to a [b][i]child[/i][/b] process you are going to need to use something like [url=http://linux.die.net/man/2/ptrace]ptrace[/url]. Otherwise the child handles are signals delivered to it. If all you want is the [i]exit status[/i] of the child then you can look at [url=http://linux.die.net/man/2/waitpid]waitpid[/url]. It will, … | |
Re: Though I am unfamiliar with the exact approach, this can be done using Xlib. It looks like createKeyEvent is what you want to look at (it uses the definitions in the header you listed) | |
Re: [code]fseek(x,-((int)sizeof(int)),SEEK_CUR);[/code] That line looks suspect to me. Why are you backtracking the size of an int? | |
Re: To answer the question about the constructor/destructor failing compilation: You need to prefix methods of a class with the class name when defining them outside the scope of the class declaration. To make that more concrete look at the following example[code]class Foo { public: Foo() { /* constructor here is … |
The End.