825 Posted Topics
Re: You could populate a vector with the values you deem valid and [icode]std::random_shuffle[/icode] that vector. At that point you could just iterate over the shuffled vector to get random values. | |
Re: Templates allow you to condense the example you gave into a more generic approach. The fact that you are both filling and reversing your vectors within you reverse* calls prevents you from doing this directly. Idealy, what you want is to combine the duplicated code between the two versions you … | |
Re: The de facto set of tools for this is [url=http://dinosaur.compilertools.net/]Lex/Yacc[/url] (Flex/Bison) What have you written your lexical analyzer in? Generally, this is tightly coupled with the parser so integrating yours with an existing tool may prove to be difficult. | |
Re: Search for ASCII escape sequences. You can use these to control how text appears on a terminal. | |
Re: If you are dealing with ethernet frames there are structures available to manage the contents. For instance, on a linux machine you might look in /usr/include/netinet/. One of the files in there is tcp.h which provides a structure that maps to the data you are trying to read. Also, there … | |
Re: strace will do a lot of work for you in terms of beautifying it's output. What you see there is the full details of a struct timeval (indicated by the [icode]{}[/icode] surrounding the values. A [icode]struct timeval[/icode] has two data members: seconds, and microseconds since the epoch. | |
Re: [QUOTE=07knev;1546110]Hi I want to boot the Laptop / Desktop via network boot CD and get connected to shared folders. Shared folder contain Ghost image ( WinXP and Win7). Please let me know how can i create a network boot CD Thanks Knev[/QUOTE] Have you looked into something like [url=http://en.wikipedia.org/wiki/Preboot_Execution_Environment]PXE[/url] booting? | |
Re: Try changing [icode]cin >> filter, season;[/icode] to [icode]cin >> filter >> season;[/icode] | |
Re: Probably ancillary to your stated problem, but what do you do when x is 0 in the following [icode](sent[x-1] == ' ') [/icode]? You are probably looking for [icode]((x == 0) || (sent[x-1] == ' '))[/icode] You probably also want to look at line 64. Perhaps [icode]x < 120[/icode] would … | |
Re: I'd suggest you not try and do the visualization from within your code unless that is the focus of your efforts (which it seems is not the case). Since there are plenty of software that exist for this purpose already (gnuplot, R, matlab, etc.) I believe it would be better … | |
Re: How about [url=http://www.cplusplus.com/reference/stl/bitset/]std::bitset[/url] or [url=http://www.boost.org/doc/libs/1_36_0/libs/dynamic_bitset/dynamic_bitset.html]boost::dynamic_bitset[/url]? | |
Re: [QUOTE=geekme;1544195]As far as description goes, I need to implement a network router and graphics do not have to be 3D.Simple and easy to learn graphics is needed to show nodes of graph and simulation of packets across a link. KIndly help.[/QUOTE] Any reason you can't use [url=http://www.isi.edu/nsnam/nam/]nam[/url] (with [url=http://www.isi.edu/nsnam/ns/]ns-2[/url])? | |
Re: I'd suggest you keep a vector of previous entries and provide an interface to access that data (or use vector iterators to do it). For instance [icode]vector::push_back[/icode] will allow you to add to the end of the vector and you can use an iterator to cycle backwards through the set … | |
Re: By the time your program is in binary form the location is known and it is an absolute jump to address. The only time this would matter (if at all) is the compilation stage. I'd argue that unless all time is dominated by compilation time you shouldn't need to worry … | |
Re: Maintain a game control loop that iterates through the movable components and updates them each 'tick' of the clock. | |
Re: Timing can be done using [icode]gettimeofday[/icode]. If you want to connect to the outside network you need to provide an address to connect to (localhost is 127.0.0.1, you dont want that). I'd suggest trying to use a connection to google at port 80 to download the search page. | |
Re: What is your project? You posted a video to a game, but I'd claim that ncurses is seldom used for games except as a thought experiment or for a particular genera. More understanding of your problem would help provide an appropriate resource or example. | |
Re: I'm not sure I understand the problem. In the example you gave all you need to do to solve for any missing parameter is to sum the negative value of the values provided. It's the same equation, regardless of the missing parameter - for any number of parameters. Are you … | |
Re: It would be helpful to see both the code and error messages about that code to expand. Does [icode]image.h[/icode] exist? Are you including it from the proper path? Do you need to link to a library to be able to use the definitions in that header? | |
Re: Please use code tags when posting code. Anytime you see an error related to 'identifier not found' that usually indicates that you've forgotten to include a header file that declares the function/variable you wish to use. In this case it might be [icode]#include <conio.h>[/icode] that you are missing (although I'm … | |
Re: Please use code tags when posting code. To answer your question: Change [icode]char letter;[/icode] to [icode]char letter = 'F';[/icode] That will initialize the letter variable to some known value and ensure that non-random data is not used if nothing else is assigned. In your case, if total is less than … | |
Re: [QUOTE=SWEngineer;1535972] [code] A::A( int iNum ) : m_iNumber( iNum ), m_bFlag(true) { } [/code] the same as: [code] A::A( int iNum ) { m_iNumber = iNum; m_bFlag = true; } [/code] [/QUOTE] Yes and No. For the simple case, the two are functionally equivalent. However, there are special cases where … | |
Re: Is thsi a C++ specific question? You might want to do this via a command line as the tools are already available for you. If you [i]must[/i] do this from within another program, I'd suggest you [icode]fork/exec[/icode] a child process and execute the ping command. Use the return value of … | |
Re: There are no [i]strings[/i] in C. There are character arrays. The [icode]str[/icode] in your above example is an array and can be used like one ([icode]str[4][/icode] for instance). If you'd like to convert that to a non-const array you will need to create storage and copy the contents. For example:[code] … | |
Re: What information about the process do you want? Is the process programmed to respond to you or do you expect to query this information without the knowledge of the program istelf? | |
Re: [QUOTE=mahendra maurya;1533551]Network statics means TCP State or UDP State...[/QUOTE] TCP and UDP state apply to connections, not to the machine. You can use built-in facilities to get an overview of all connections on a local machine but the programs differ from platform to platform ([icode]netstat[/icode] is available on *nix flavors). … | |
Re: [QUOTE=jnewing;1533965]so what i'm trying to get my head around it say i have a vector of vectors containing some unsigned chars and i want to copy a certain vector to another vector as follows. ... How can i go about doing this? [/QUOTE] Do you want to have a [i]copy[/i] … | |
Re: In addition to the methods described above I find that [i]reading[/i] other code is terribly beneficial. Find a medium sized project on sourceforge or github and just get familiar with the way other people write code: what's good, what's not. The more exposure you have the more base you will … | |
Re: File descriptors are just integers. The management of them is hidden from you, the user, but when they are provided it seems that open will select the lowest integer not currently associated with an open file for your process. In general, stdin, stdout, stderr are referenced internally using file descriptors … | |
Re: In addition to what Fbody mentions, including an entire namespace can hide subtle errors in code (especially for beginners). Consider the following:[code]#include <iostream> #include <algorithm> using namespace std; int main () { int x = 5, y = 3; cout << "Before swap: " << x << " " << … | |
Re: I'd suggest something more along the lines of[code]int DSum2 (int v) { if (v < 10) return v; return DSum2 (DSum (v, 0)); }[/code]It's important, though, that you understand [i]why[/i]. Work through the solution (yours and this one) and record each step. The beginning of this one would look like:[code] … | |
Re: [QUOTE=pratik_garg;1525005] But you have forget one thing to compare node number in both the list. [/QUOTE] It really depends on what a 'set' constitutes here. Remember, in its truest form, a set has no duplicates so converting an array (or list) to a set can change its size. For instance[code]List: … | |
Re: No. In order to do what you want you need to 'wrap' the type in a class and provide operators through that interface. | |
Re: [QUOTE=Shruti4444;1526030] I tried doing it with vectors..[/QUOTE] The point is that we would like to see what you've done so far so we can help you. The fact that you have not finished this indicates that you have specific errors. If you describe these errors with some relevant code snippets … | |
Re: [code]class Unit { int x_; public: Unit(int x) : x_(x) {} }; class Soldier : public Unit { int soldier_specific_stuff; public: Soldier(int x, int y) : Unit(x), soldier_specific_stuff(y) {} Soldier(int y) : Unit(default_unit_stuff), soldier_specific_stuff(y) {} };[/code] You can pass items to the constructor of the base class in the initializer … | |
Re: I'd try and stay away from allowing the mutual dependency between the two processes. If either of the two of them could fail (another question is [i]why[/i] is it ok for them to fail) then you have a bad race condition. It might not fit what you want to do … | |
Re: [icode]enum -> int[/icode] is a one-way street. You can not convert [icode]int -> enum[/icode] directly. What you can do is redefine [code]void setMode(VideoOutPutMode mode)[/code]as[code]void setMode(int mode)[/code] [b][u]HOWEVER[/u][/b]... The former version (the one with the enum) provides direct control over the values that can be passed into that function. You do … | |
Re: It is the size (in bytes) of the memory you want to request. In general, you determine this with the [icode]sizeof[/icode] operator as with your first example. | |
Re: Any chance you can wrap the library headers in a separate namespace? Something like:[code]// in foo.hh class Foo {}; // in foo.cc namespace hidden { #include "foo.hh" } int main () { Foo foo1; // Fail do to namespace wrap hidden::Foo foo2; // works as you would expect // ... … | |
Re: There is [i][b]very[/b][/i] little context here with which to operate, but my guess is that you need to clear the attributes you set on your screen after the output before trying anything else. | |
Re: [icode]printf[/icode] and [icode]scanf[/icode] take [roughly] the same set of format characters. Read the manual pages on either of the two and look for 'hex'. [url=http://www.manpagez.com/man/3/scanf/]Here[/url] is a starting point. | |
Re: By default, operations such as [icode]scanf[/icode] split on whitespace. All that remains is to be able to not overflow buffers and to recognize when the stream has reached an invalid (or empty) state. What exactly are you having trouble with? | |
Re: You can create locally-scoped variables within a specific case statement similar to[code] switch (x) { case 1: { /* Things created here are local to the case 1 statement */ } // ... }[/code] However, you should always include the { } and, as you have found out, you can … | |
Re: A singleton is a design pattern. It is a way to describe a class that get instantiated only once but can be shared by many callers. Here is an example:[code] class Timer { int x; Timer () : x(0) {} // Private static Timer * only_copy; public: static Timer * … | |
Re: The C language supports mathematical operations. For instance[code]#include <stdio.h> int main () { int x = 1 + 2 + 3; printf ("%d\n", x); return 0; }[/code] Will output [icode]6[/icode]. I dont see an apparent pattern in your numbers so I'm not entirely sure what the [icode]...[/icode] is to stand … | |
Re: [icode]recv[/icode]'s second argument is a buffer, [b]not[/b] a [icode]FILE*[/icode]. You likely need something like:[code]FILE * fout = fopen (...); unsigned char * buff[255] = {0}; n = recv (newsockfd, buff, 255, 0); // ... fprintf (fout, "%s", buff); // ...[/code] | |
Re: You dont [i]put things in cin[/i]. cin is a stream operator; you use it to extract elements from a stream. As an aside, the language of your post will (in the general case) cause less people to respond seriously. 'Q' is not a suitable substitution for 'Question'; juz is not … | |
Re: I found it helpful when I was learning recursive behavior to write the function out at each step with indentation. For instance, given the following:[code] int fun (int n) { if (n < 1) return 1; else return 1 + fun (n - 1); }[/code] I would write it out … | |
Re: [icode]vector<X*> Ccontainer;[/icode] is a vector of pointers. You call the [icode]>>[/icode] operator with a pointer as an argument ([icode]a.Ccontainer[i][/icode]) but define it as taking a reference ([icode]operator>>(istream& in,X& x)[/icode]). Thats the best I can tell without you describing the actual error you are experiencing. |
The End.