825 Posted Topics
Re: The if/else construct is as follows:[code]if (condition) { // body of if } // ---- if (condition) { // body of if } else { // body of unconditional else } // ---- if (condition1) { // body of if } else if (condition2) { // body of else if … | |
Re: In C++ you allocate memory with [icode]new[/icode] and the initialization takes place in the constructor. You do not use [icode]malloc[/icode] and [icode]free[/icode] as the proper initialization and cleanup routines will not be invoked. If you are creating a non-dynamic structure then the constructor is invoked at object instantiation and you … | |
Re: How would you suggest handling the following?[code]void Foo (int i) { if (i > 0) Bar (i - 1); } void Bar (int i) { if (i > 1) Foo (i - 1); }[/code] | |
Re: Why are you using pdcurses software to work through an ncurses tutorial? By definition there will be differences. Is there a reason you are not just using ncurses? | |
Re: This is not a c++ question. However, the [url=http://tldp.yolinux.com/HOWTO/RPM-HOWTO.html]web[/url] has many resources. | |
Re: You place a [icode]cout[/icode] statement to check for a value and then as for input to change that value again before using it. What is the reason of your call to [icode]getline[/icode]? | |
Re: [icode]find_if[/icode] returns an iterator. You should compare that to [icode]load.end ()[/icode] if you want to see if it succeeded. Then just use the iterator. [code]std::vector<std::string>::iterator vit = std::find_if(load.begin(), load.end(), StartsWith(thisString)); if (vit != load.end ()) { // do what you want with the iterator here }[/code] | |
Re: As [b]DJSAN10[/b] mentions this is undefined behavior. You will not get a clearer explanation than in the already mentioned thread: [url=http://www.daniweb.com/software-development/c/threads/405549/1732048#post1732048]Narue's comment[/url] | |
Re: The problem with your approach (and the one [b]subith86[/b] suggests) is that the environment variables you are setting are valid [i]only for the shell they are executed in[/i]. So when you call [icode]system[/icode] or [icode]putenv[/icode] you are respectively writing to a new shell that goes away after the [icode]system[/icode] call … | |
Re: Doing this in pure shell is a poor approach IMHO. My suggestion would be to use something such as Perl, Python or Ruby to parse the input. In Ruby you might use something like:[code=ruby]#!/usr/bin/env ruby require 'cgi' line = "2009-12-16 00:00:43,970 INFO [btpool0-12194://webmail.amit.com/Microsoft-Server-ActiveSync?Cmd=Ping&User=rahul%40kke.amit.com&DeviceId=androidc986729649&DeviceType=Android] [] sync - POST Microsoft-Server-ActiveSync?Cmd=Ping&User=ritesh%40kke.amit.com&DeviceId=androidc986729649&DeviceType=Android" if line … | |
Re: Well, I don't know what [icode]BUFLEN[/icode] is but if you set your reads and writes to a specific size (i.e. [icode]sizeof(data_type)[/icode]) then you don't need to worry about how much is written and when since the [icode]SOCK_STREAM[/icode] guarantees proper order and the sizes are fixed. If you can not reliably … | |
Re: If you are looking for ease of use and understandability Ruby has a gem called [url=http://treetop.rubyforge.org/]Treetop[/url] that is pretty straightforward. You will have to be comfortable with Ruby, however. If you go the more traditional C/C++ route the de facto tools are lexx/yacc (or flex/bison). These are fairly heavyweight and … | |
Re: Instead of storing the entire line as a string, why not map the two values to key/value entries into a [icode]std::map[/icode]? Something along the lines of[code]while (file1.good ()) { file1 >> ids; file1.getline (val, VAL_SIZE); lut[key] = val; } // Then to look up a certain key... if (lut.find (ids_key) … | |
Re: This depends on how you manage the reboot and sending of messages. For instance, using TCP, after a reboot you will need to reconnect do to the nature of the stream connection. If the server is OK with this and can take connection requests from clients then simply have the … | |
Re: One way that might be effective for you is to create a syntax tree based on the commands you support. For instance, the root of the tree is empty and the first level of the tree is all the verbs you support. The node below each supported verb could be … | |
Re: There are a few errors in your code. First, [icode]char delims[] = " ", "\n";[/icode] is invalid and your compiler should have told you so. You probably want something like [icode]char * delims = " \n";[/icode] Also, [icode]if (delims = " ")[/icode] is an assignment statement and in your code … | |
Re: One critical error I see is that you are indexing your arrays starting at 1. In C++, arrays are indexed from 0 to n-1 where n is the number of elements in the array. This means that in some of your loops you are accessing one past the end of … | |
Re: This sounds very much like an assignment you are to complete on your own. What have you investigated so far? What conclusions have you reached? | |
Re: [QUOTE=Kanoisa;1729369]Can i use my ifstream file object with the cstyle fseek operation or do i need to figure out some kind of a workaround for that?[/QUOTE] [url=http://www.cplusplus.com/reference/iostream/istream/seekg/]seekg[/url] | |
![]() | Re: You may want to look into the [url=http://pm-utils.freedesktop.org/wiki/]pm-utils[/url] package. Have a look at [url=https://wiki.archlinux.org/index.php/Pm-utils#Creating_your_own_hooks]this[/url] for the behavior you are specifically after. |
Re: To set an environment variable you usually export it in your shell configuration file. For instance, in [icode]bash[/icode] you would add an entry such as [icode]export CLASSPATH="/path/to/add:${CLASSPATH}"[/icode] to your [icode].bashrc[/icode]. Other shells may require a different syntax. It is hard to tell what problems you are having when you describe … | |
Re: If you want to support a small set of commands you can do so directly with a [icode]std::map< std::string, std::string >[/icode]. Simply read in tokens and map them to appropriate commands. If you want to support something more complex, as [b]ravenous[/b] suggests, you will have a bit more work to … | |
Re: MySQL provides [url=http://dev.mysql.com/doc/refman/5.0/en/c.html]some information[/url] | |
Re: In general, it is easier to run client/server test code in separate consoles. However, this requires a separate client and server. If you've combined them then you really have no choice but to force a particular order of operations and to 'take turns' | |
Re: Data rate of the devices is fixed. Higher layer compression strategies do not change that value. Perhaps you are interested in the total goodput increase based on compression? | |
Re: Routers don't normally care. There are special cases such as throttling but these are not the general case with routers. Routers care about how to [i]route[/i] packets (frames, actually). The necessary information for that is determined on a frame-by-frame basis. A frame is received, the header is parsed, a source … | |
Re: HTTP is an application-layer protocol, TCP is a transport-layer protocol. You can not necessarily infer semantics of one from the other. To do what you are after you need to follow the HTTP [i]session[/i] and connect that with the TCP [i]streams[/i] related to it. There are tools that do this … | |
Re: Perhaps try starting [icode]screen[/icode] in detached mode. Something like:[code]$ screen -d -m minecraft[/code] | |
Re: You could [url=http://en.wikipedia.org/wiki/Plagiarism_detection]search the web[/url] | |
Re: [QUOTE=namratag;1694856]How to get value from key in map?[/QUOTE] A map can be indexed by the key to retrieve a value. So, given the key [icode]key[/icode] and the map [icode]table[/icode], you could get the value for key by way of [icode]table[key][/icode]. | |
Re: The [icode]cin >> i1[/icode] is a [i]blocking[/i] call. That means it will wait forever for input to be available and you will not reach the sleep until the user enters something. You can wait for input to become available in linux by using [icode]select[/icode]. Example:[code]#include <stdio.h> #include <sys/select.h> int main … | |
Re: Several observations about your code: [icode]string_dig1 = (char *)malloc(sizeof(char));[/icode] Allocates enough room for a single character - not an entire array of them. You need to allow for the largest input data you expect to get and take precautions against values greater than that. The fact that things have not … | |
Re: Either form should work correctly:[code]echo -e "$1\n$2\n" | cat >> $file # Or echo -e "$1\n$2\n" | cat - >> $file[/code]In the second form it is explicit that STDIN is the input file. Perhaps you should present a minimal working example of what fails so we can duplicate (including input/output … | |
Re: Considering your original example line 27 is empty. Perhaps is would help us if you provided your updated source file. | |
Re: You can place code to be executed in your lex source file and provide an implementation during compile time. A short example: [code]------ ex.l ------ %% a { foo (); } %% int main () { yylex (); return 0; } ------ ex.c ------ #include <stdio.h> void foo () { … | |
Re: I've already [url=http://www.daniweb.com/software-development/shell-scripting/threads/400231]answered[/url] you. | |
Re: What motivates you? Pick something that keeps you interested and find an unsolved problem in that space. That's about the extent of the equation. ![]() | |
Re: Reading the contents into a variable is a simple task. Something like[code]VAR=`cat the.file`[/code]should do the trick for you. However, if you plan to access that data as an array of values (I'm assuming that this is your intent) then that will not work directly. To do that in Bash you … | |
Re: I generally use the following syntax in Bash[code]if [[ "${STR3}" == "${STR1973}" ]]; then # This is match condition fi[/code] As an aside, it is generally more useful to you to experiment yourself with these types of trivial problems. | |
Re: [QUOTE=D19ERY;1714265]how would i incorporate the - a and - h features?[/QUOTE] See [url=http://www.mkssoftware.com/docs/man1/getopts.1.asp]getopts[/url] | |
Re: [icode]sizeof[/icode] is a compile-time operation. The [icode]#if[/icode] is part of the translation phase (which happens before compilation). So you can not use the compiled results [i]before[/i] it is computed. You can either use a type that is designed for this already ([icode]uintptr_t[/icode]) or have your build system pass the value … | |
Re: What have you tried so far? This is pretty straightforward and we will not do your homework for you. Topics to look into: [icode]${#}[/icode]: Number of command line arguments [icode]tr[/icode]: Translate between sets of characters [icode]ls[/icode]: Directory listing [icode]echo[/icode]: Printing to output device [icode]-d[/icode]: File test for directory You will … | |
Re: Usually, you'd like to spawn the process in the background and [icode]wait[/icode] for it to complete. Unfortunately, there is no timeout parameter to the wait call. I can think of two immediate solutions. First, you can write a small C program that will execute the recovery script and timeout after … | |
Re: [icode]pointer = sharedmem;[/icode] is pointer assignment. You will want to do a [icode]memcpy[/icode] to have that work the way you'd like. | |
Re: What are your thoughts on the matter? We could certainly help correct any mistakes in your conclusions. | |
Re: Any chance you know [url=http://www.daniweb.com/software-development/shell-scripting/threads/389077]this person[/url]? My suggestion in that thread was that [icode]cut[/icode] and [icode]grep[/icode] are the wrong approach. | |
Re: The HTTP format is very well specified ([url=http://www.w3.org/Protocols/HTTP/1.0/spec.html]see here[/url]). You can simply pull apart the fields you need and ignore the ones you do not. That aside, I think that [b]wingless[/b] provides the best advice: use existing software. | |
Re: You will likely want to break the problem down into two distinct parts: parsing input and managing the increment. If you parse the input properly then the increment should be trivial with the exception of propagation of the carry. | |
Re: Your probably mean to do something along the lines of [icode]if id > 1[/icode] instead of [icode]if id > '1'[/icode]. Notice the lack of single quotes in the first example. |
The End.