825 Posted Topics

Member Avatar for nayefc

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 …

Member Avatar for L7Sqr
0
209
Member Avatar for d_panayotov

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) …

Member Avatar for L7Sqr
0
129
Member Avatar for jackmaverick1

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.

Member Avatar for jackmaverick1
0
158
Member Avatar for initialise

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 …

Member Avatar for initialise
0
7K
Member Avatar for geekme

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 …

Member Avatar for L7Sqr
0
110
Member Avatar for aleemoe

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] …

Member Avatar for L7Sqr
0
83
Member Avatar for jambul_16

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. …

Member Avatar for rubberman
-1
107
Member Avatar for Swiftle

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 …

Member Avatar for L7Sqr
0
115
Member Avatar for liphoso

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] …

Member Avatar for liphoso
0
148
Member Avatar for himgar

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 …

Member Avatar for L7Sqr
0
89
Member Avatar for biancaW

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 …

Member Avatar for L7Sqr
0
407
Member Avatar for L3gacy

[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.

Member Avatar for L3gacy
0
207
Member Avatar for RyanMcMillan

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 …

Member Avatar for Fbody
0
544
Member Avatar for kyxler

What have you tried so far? Help is not free - especially the kind of help you are asking for.

Member Avatar for RyanMcMillan
0
87
Member Avatar for JordanHam

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 > …

Member Avatar for JordanHam
0
4K
Member Avatar for subith86
Member Avatar for hohoho89

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 …

Member Avatar for hohoho89
0
2K
Member Avatar for pikachoo

For static analysis, there is another tool that is very powerful: [url=http://www.splint.org/]splint[/url]

Member Avatar for L7Sqr
0
79
Member Avatar for vineeshvs

[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.

Member Avatar for Akash Saikia
0
154
Member Avatar for agarg12

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.

Member Avatar for agarg12
0
134
Member Avatar for blee93

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] …

Member Avatar for frogboy77
0
209
Member Avatar for ctpsolo

[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.

Member Avatar for ctpsolo
0
194
Member Avatar for jephthah

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.

Member Avatar for Ancient Dragon
0
486
Member Avatar for anu07

[icode]while(1);[/icode] Drop the semicolon. ([icode]while(1)[/icode])

Member Avatar for anu07
0
852
Member Avatar for akase2010

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 …

Member Avatar for Fbody
0
130
Member Avatar for borich_cj

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 …

Member Avatar for caut_baia
0
313
Member Avatar for Staggasaurarts

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 …

Member Avatar for ziggystarman
0
1K
Member Avatar for user543820

[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 …

Member Avatar for Ancient Dragon
0
174
Member Avatar for PerplexedWon

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.

Member Avatar for PerplexedWon
0
203
Member Avatar for b56r1

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 …

Member Avatar for L7Sqr
0
147
Member Avatar for lochnessmonster

[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 …

Member Avatar for vijayan121
0
157
Member Avatar for dvongrad

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[ …

Member Avatar for dvongrad
0
308
Member Avatar for akase2010

Outside of changing [icode]array[index][/icode] to [icode]*(array + index)[/icode] everywhere I'm not sure I understand what you need to do...

Member Avatar for template<>
-2
125
Member Avatar for c+-

The class declaration [i][b]is[/b][/i] the prototype of the member function (with optional definition).

Member Avatar for template<>
0
513
Member Avatar for MasterGberry

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]

Member Avatar for MasterGberry
0
83
Member Avatar for daviddoria

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.

Member Avatar for mike_2000_17
0
110
Member Avatar for Legend32A

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 …

Member Avatar for Legend32A
0
98
Member Avatar for Utsav Chokshi

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...

Member Avatar for nezachem
0
244
Member Avatar for vineeshvs

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 …

Member Avatar for vineeshvs
0
406
Member Avatar for reemhatim
Member Avatar for triumphost
Member Avatar for Dingbats
0
2K
Member Avatar for kandarpa

You can always use the [icode]/proc[/icode] filesystem which includes entries for all currently running processes.

Member Avatar for triumphost
0
11K
Member Avatar for silverpanda

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, ',' …

Member Avatar for jonsca
0
388
Member Avatar for lochnessmonster

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 …

Member Avatar for L7Sqr
0
207
Member Avatar for stevanity
Member Avatar for ontherocks

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 …

Member Avatar for Narue
0
175
Member Avatar for cbreeze

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, …

Member Avatar for L7Sqr
0
244
Member Avatar for jainpratik2

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)

Member Avatar for L7Sqr
0
4K
Member Avatar for yoshitsugu

[code]fseek(x,-((int)sizeof(int)),SEEK_CUR);[/code] That line looks suspect to me. Why are you backtracking the size of an int?

Member Avatar for L7Sqr
0
188
Member Avatar for COL_Milkshake

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 …

Member Avatar for COL_Milkshake
0
3K

The End.