raptr_dflo 48 Posting Pro

No idea, especially since the line-numbering in the code you provided doesn't correspond to the line-number in the error messages. Perhaps replacing the '.' with another '::' would work?

_FtpWebRequest->Method = System::Net::WebRequestMethods::Ftp::UploadFile;
raptr_dflo 48 Posting Pro

So what should the find() method be operating on? So far, GreyWolf has written the only code here, other than your definition of your struct. Where's -your- code?

raptr_dflo 48 Posting Pro

Well, what holds the data for the stack? And where is the top element in that data? I'll post the correct code in a couple hours (if I remember), but see if you can get it first! :)

raptr_dflo 48 Posting Pro

And when you post your code, please also mark the thread as "solved". Great work! :)

raptr_dflo 48 Posting Pro

Right at line 1, you've omitted the class-name, unless that was a copy-and-paste error:

string Vigenere::encode(string text){

Could that be the problem? Otherwise, your code looks fine. Try one more cout right before your return from encode():

cout << "final encrypted text: " << line << endl;
raptr_dflo 48 Posting Pro

Your code looks ok at first glance, as far as adding integers. Have you tested it yourself? If it doesn't work, what is it doing wrong?

Ravenous' code will certainly get the information from the text file, but at his line 20, his comment tells you that you now have to parse the information out of the line that you read from the file and do something with it.

Now that you have a line (instance of string), you can create a stream from it:

stringstream inTxt (line);

.
Then you can use inTxt pretty much exactly the way you use inFile, to read items out of line. You just need to check when inTxt is empty (use one of .good(), .bad(), .eof()) so you know when to get another line from inFile. If you are sure that integers and operators will always be separated by whitespace, you could read a string out of inTxt each time, and provide and call your own functions isInteger() and isOperator(). You could declare isInteger as:

bool isInteger(const std::string & str, int & val);

and have it return true if str represents an integer (and store the integer value into val), or false if str does not represent an integer (and leave val alone).

If the input can skip spaces between integers and operators, e.g. 3+5 instead of 3 + 5 , then you may need to iterate over line one character at a time, deciding what to …

raptr_dflo 48 Posting Pro

I haven't tested it, so apologies if I have any syntax errors in it, but try this:

string Vigenere::EraseChar(string str){
    for(int i = 0; i < str.length(); i++){
        bool inAlph = false;
        for(int j = 0; j < 21; j++){
            if(str[i] == ALPH[j]){
                inAlph = true;
                break;  // don't need to keep checking against the rest of ALPH
            }
        }
        if (!inAlph) {
            str.erase(i,1);
            i--;
        }
    }
    return str;
}
raptr_dflo 48 Posting Pro

Also at line 99, what are you returning from top()? And what did you mean to return? Also, you have an assignment instead of equality-test at line 38, but I don't know what the expression is supposed to do. A close-character will never equal its open-character, and any other non-null character will ever equal the null-character. Or if you're replacing each close-character with its corresponding open-character, and all other chars with null-characters, and proceeding into the if-block only for paren/bracket/brace, that's fine, but it's not exactly human-readable. :)

Maybe instead, you could consider separate functions bool isClose(char) and char openCharForCloseChar(char) , and use those in your logic without replacing the actual characters in line[].

raptr_dflo 48 Posting Pro

Read the code you just posted, carefully. First, what are you returning? Once you fix that, if you can't see what's wrong with the code, try inserting cout << "str = '" << str << "'" << endl; before line 2, and again after line 7.

There's nothing like debug-prints for tracking down problems!

raptr_dflo 48 Posting Pro

As far as cleanliness, I don't know offhand if you need to resize your QBitArray before assigning into it, but since you know it will be the same length as your input codeString, why not start off with:

QBitArray codeArray(codeString.length());

and skip the resizing completely?

Also, the QBitArray documentation says:

For technical reasons, it is more efficient to use testBit() and setBit() to access bits in the array than operator[]().

Good luck!

raptr_dflo 48 Posting Pro

Instead of writing out to your output file every time you do something, try separating your logic into:
1) read the input file into your array
2) loop over user input, adding students to the array, removing students from the array, or editing students already in the array
3) when the user chooses "Quit", write the student array out to the output file

Consider having your search-routine return the array-index of the student you're searching for (and maybe an obvious non-index like -1 if the search fails).

Your edit function shouldn't do a search. Instead when the user chooses the "Edit" option, first perform a search using your search function, and if successful then call your edit function, otherwise print an error message that the specified student wasn't found.

raptr_dflo 48 Posting Pro

Continuing on, yes, no need to call line a "variable" in quotes. It IS a variable, so of course you can treat it like one. So are inFile and outFile.

inFile is called an "instance" of class ifstream. outFile is an instance of class ofstream. line is an instance of class string. See this for a list of supported operations on string instances. There are also good tutorials on that site.

raptr_dflo 48 Posting Pro

You have a spurious semicolon at the end of line 74.

Your EraseChar() method is still incorrect. See what happens if you have two or more successive characters not in the range 'A'-'Z'.

In encode() and decode(), what is the value of k_index if key isn't one of the characters in ALPH? Same for t_index and text? If key and text are only supposed to contain characters from ALPH, then you still need to rewrite EraseChar() to remove the non-ALPH characters.

Try adding cout lines after you've called StringToUpper() on key, and again after you've called EraseChar(). Make sure your input key has a mix of lower and upper-case letters, both within ALPH and not, along with some numbers and punctuation symbols, to make sure those two functions are working as intended.

raptr_dflo 48 Posting Pro

So you're trying to write a 'bot which might, for example, automatically click into the fields on a displayed web-page and enter specific text data for you?

Anyway as far as your mouse-link, the first note at the top of the page says the function has been superseded, and provides a link to the updated function to use instead. As far as "getting code to compile using your compiler", it looks like you're one of very few users on this forum using the latest and greatest tools on Windows, so what exactly is the problem you're having compiling your code?

raptr_dflo 48 Posting Pro

Hmmm, while I couldn't reproduce it, I wonder if the problem is the lack of a space between "#include" and "<iostream>" -- it sounds like it's ignoring the # and trying to do something template-like.

BTW, which version of gcc are you using? gcc --version . I have a relatively old "g++.exe (GCC) 3.4.5 (mingw-vista special r3)" because of some of the libraries I need to link against. :)

raptr_dflo 48 Posting Pro

Your code in check_num() is fine (other than not maintaining leading zeroes, as Ketsuekiame pointed out). Instead you have a subtle error on line 71. Can you spot it yourself?

While it doesn't matter, since you're not changing a, b or c within check_num(), you don't need to recover the values back in the caller. Therefore you don't need to pass them by reference, and line 48 can be int member :: check_num(int a,int b,int c) .

raptr_dflo 48 Posting Pro

Several problems:

You declare variables like ROWS, COLS, ALPH and VIG internally to your Table() method, so they are not accessible out side of it. Fix this by making them members of your Vigenere class, and then either:
+ pass 'alphabet' into your Vigenere::Vigenere() constructor and initialize them there, or
+ leave them uninitialized until you call your Table() method

Your EraseChar() method doesn't erase non-Italian letters out of the A-Z range. While it's probably slower, consider comparing each character in the input str against each character in ALPH.

Use the same EraseChar() method on key, in your constructor at line 8 above. The code in the constructor is almost the same as in EraseChar(), but is broken since you don't decrement i when you remove a character.

At line 14, it looks like you're trying to re-extend your key to be the same length as your text, but you don't have a text variable at that point, you're trying to append characters from the key that don't yet exist in it (when cnt is > key.length()) onto the end of it, and the test for lengths-not-equal is redundant (checking less-than is sufficient).

Let's get that much fixed and then see what problems remain.

raptr_dflo 48 Posting Pro

You don't generally "change" the command-line arguments. You either specify them or not, as needed and as dictated by the program. If you're running your program by double-clicking on a desktop icon, you don't have a command-line, so you don't get to specify any arguments. But more modern user-interactions methods, such as dragging a text-file-icon onto an editor-application-icon to run the editor program with the text-file pre-loaded for editing is a fancy version of specifying the (optional) text-file path on the command-line when starting the editor.

As far as which to use (assuming you're running from a command-line, such as the "Command Prompt" in Windows or a shell in cygwin or an equivalent terminal window on Mac, Linux, etc.), both have their uses.

In addition to specifying start-up environment/state for a program, a config-file can be made read/write and can store user preferences made while the program is running -- this is more-or-less how all the various apps' info gets saved in the iPhone's "Settings" tool. While the underlying implementation details may differ, you can think of it as reading and writing a config file for each installed app, and then the app also reads its config file on start-up.

The command-line is better suited for information specific to that specific run of the program, but can also be used to override configuration values on an as-needed basis -- faster than editing the config-file and then changing it back later.

As far as the specific arguments …

raptr_dflo 48 Posting Pro

but then does that mean for the level 2 clips i would have to declare another SDL_Rect in the class? and for the rest of the levels the same?

I'm not sure. The code you've posted in your Google Doc appears to declare the SDL_Rects as global variables. Which class and specific SDL_Rect are you referring to?

and i will have to make different set_clips() functions for the different level platforms?

Your set_clips() method looks generic enough to be reused. You would just call it again for the platClipsp[] array of RECTs for the next level platform.

is there no way in which i can use one function and SDL_rect to do the above?

There's always a way, but that's not necessarily the best solution. Clean, clear, well-thought-out code isn't required to get a program running, but it helps a great deal when you want to come back and fix something you missed the first time, or add a feature.

I may be wrong, but it sounds like you don't really have a firm sense of which classes should be responsible for various aspects of the functionality. I don't know what all of these various Clips are (maybe bounding-rectangles for collision detection?) or why they're global variables instead of attributes of various class instances, but maybe if you slow down, and think about what the objects are in your game, the answers will become obvious: so far you have a "Stick" (the guy you move around?), a …

raptr_dflo 48 Posting Pro

This time, you have defined

SDL_Rect levelOnePlatform [1];

but you're still calling

levelOne.set_clips(levelOnePlatform, 50);

which is probably overwriting all kinds of other memory!

raptr_dflo 48 Posting Pro

Correct enough. SDL maintains the queue of events for you, so all you're doing is checking whether there's an event on the queue and if so, retrieving it so you can decide what to do about it.

After line 7, consider adding a 'break;' statement so that you don't have to check whether the event-type is all of the other possible options before exiting the event-queue-polling loop (which you have to do at -some- point anyway, so that you can get back out to the while(program) loop).

raptr_dflo 48 Posting Pro

Anuradha,
You said in your original post:
>> This is my code .I want to print the numbers whose only prime factors are 2, 3 or 5.

If you want to print the first 12 primes, that's a different exercise!

1 is not a prime number (by consensus, as it's also not a product of prime factors, it's just a special case). Each number greater than 1 is either a prime number or is the product of some set of prime factors, each of which is smaller than the number:
2 is prime, 3 is not divisible by 2 so 3 is prime, 4 is the product of 2 and 2, and so on. Each time you discover a prime, print it out and increment your counter, until you have printed however many you want (in your case 11).

int count = 0;
int potential = 2;
while (count < 11) {
    bool is_prime = is_num_prime(potential);  // determine if potential is prime
    if (is_prime) {
        cout << potential << " is prime" << endl;
        count++;
    }
    potential++;
}

I've left the is_num_prime() function for you to complete (if any number smaller than the number you're testing divides it evenly, then the number is not prime -- there are a number of efficiencies you can make -- think about: which numbers should you divide by? when can you stop?). Get it working first, then do a search on "sieve of eratosthenes" for an approach to …

raptr_dflo 48 Posting Pro

It is also generally considered "a bad thing" to use global variables, as you have declared in lines 16-19. Instead you should pass the ones you need to each function: by reference for "output" values that the function should alter, and by copy (or const reference) for "input" values. Conversely, if you're going to make all the variable global anyway, you don't need to pass any of them into your functions.

Is there a reason you loop over your input/convertToMinutes/convertBack/output 12 times for the first customer? If you don't reset count, you won't loop at all for your next customer(s).

Your upper-limit validation for hours and minutes are incorrect in opposite directions: 25 is not a valid hour (but will pass), 59 is a valid number of minutes (but will fail). What happens if the customer enters at 23:30 Friday night, and leaves at 1:30 Saturday morning?

raptr_dflo 48 Posting Pro

You should also consider printing something besides the initial "1" if you want to see a list of numbers.

If a number's ONLY prime factors are 2, 3, and/or 5, then you should be able to divide evenly by some quantity of each of those factors, and be left with 1.

bool factorsAre2And3And5(int val)
{
    if (val < 1)
        return false;
    while (val > 1) {
        if (val % 2 == 0)
            val /= 2;
        else if (val % 3 == 0)
            val /= 3;
        else if (val % 5 == 0)
            val /= 5;
        else
            break;
    }
    return (val == 1);
}
raptr_dflo 48 Posting Pro

Try the following:

// return a non-cost reference
    std::string & access(int row, int column);
    // returns a const reference, second const indicates that the method
    // doesn't alter the grid-instance that you're accessing from
    const std::string & access(int row, int column) const;

    ...

    csv_File & grab(int index);
    const csv_File & grab(int index) const;

If you're still getting compiler errors, provide more of the source code and specify which line is generating the error.

raptr_dflo 48 Posting Pro

It's generally considered bad form for one application to steal events from all other applications. I'm betting (with good cause) that you can do what you need, which means making sure that the keyboard events are passed to your application -before- they're passed to the application that currently has focus ... if you don't want to (or can't) tell the system that your application should keep focus until it says otherwise (or terminates). Depending on why you need the F5 keypress event sent only to your special application, there may be some other way to achieve the same end. I'm not going to pry, but if this were easy to do, the solution would be ubiquitous and well-documented, and probably none of your applications would work correctly because some other application would be stealing the events it wants. :)

raptr_dflo 48 Posting Pro

No trouble at all. Please mark your thread as "solved". :)

raptr_dflo 48 Posting Pro

Glad to hear it! Please mark your thread as "solved". :)

raptr_dflo 48 Posting Pro

First of all, you search for the father, then the mother, then the father again, then the mother again. It will be more efficient to search for the father first, and grab the auxID and the level at the same time; then repeat for the mother.

That said, I don't recall from your earlier thread how your member names correspond to the order of data elements in your table. So which element to update is unclear, but for each time through the loop of your people-sorted-by-auxID (from the name of your map variable), you wish to assign a sequentially increasing "code" value? Or is it possible that some "people" already have code values, so you need to make sure you start above that? If the former (everyone gets a new code value), then it's sufficient to include an integer counter in your outer loop control:

int next_code;
    for (it4 = IndivAuxIDSortedMap.begin(), next_code = 1;
         it4 != IndivAuxIDSortedMap.end();
         ++it4, ++next_code)
    {
        ...
        receiveLastCode = next_code;
    }

Note the commas separating the items within each functionality block (initialization, termination-expression [no change here], update), as opposed to the semicolons separating them.

If assigning the next_code is dependent on a condition, then instead initialize it to 1 at the beginning, and then increment it immediately after assigning it to a person.

raptr_dflo 48 Posting Pro

Heh, the last function looks great. Consider the possibility that (for some reason) you have only one valid button to draw. (Hint: the problem is actually in your Menu constructor, and has been discussed and re-discussed so many times in this forum that there's a sticky topic for it at the top of the C++ topic list!)

If the hint isn't helping, start inserting debug "cout <<" statements everywhere that makes sense, such as at the end of your Button constructor function to print out all the member values. Good luck!

raptr_dflo 48 Posting Pro

And there's no bigger help than inserting printf/cout statements to show you exactly which blocks of code are executing (and the values of variables too). They're easy to insert and easy to remove. If you want to get fancy you can define your own "logging system" so that you can print out information at various levels of importance, and set the importance level(s) you're interested in.

raptr_dflo 48 Posting Pro

Back to your question, though, you need to implement the Polynomial constructor taking arbitrary coefficients (inserting code in your "main file" before line 17) ... the code in the following variant of the constructor (lines 20-27) is already close.

You also need to implement polynomial addition in method operator+().

Finally, it looks like your operator<<() and operator>>() aren't parallel (you output a different format from the one you input), though that may be intentional.

raptr_dflo 48 Posting Pro

I wrote a fairly substantial two-way socket-based communication program over a year ago. If you have a basic client-server model working (server listens for connections on a particular port, client [or multiple clients] opens socket connections to the server's port, issues a command, reads until a response returns, and then maybe issues another command, and so on, and closes the socket when done), then you don't need to "reverse" much.

Assume that the "client" still controls the socket connection and will close it when finished. Then in order not to block while waiting for input, each side needs a loop that checks whether there is input waiting to be read or output waiting to be sent. If the socket communication is placed in its own thread, then a queue can be used to store up outbound messages until the socket loop is ready to send them. If there's any chance that data in one direction could prevent data from going the other way in a timely manner, then use a flag variable to switch between "check for something to receive" and "check for something to send" and bounce back and forth each time through the loop. Getting the code correct is not trivial! See how far you can get with this much. Good luck!

pissman commented: Very good ! and helpful +0
raptr_dflo 48 Posting Pro

There's a very suspicious "endl" being output in your center() function. Instead, I think you want to output a certain number of spaces, then the passed-in string, then another certain number of spaces, so that you've filled the width of the column.

raptr_dflo 48 Posting Pro

It would greatly improve readability if you used consistent indentation in your code. That said, one very likely problem is the usage of mapface.erase() within the loop of the iterator over items in mapface. Since you pick your range of elements from mapface as the first N with the same index-pair as the first element, use the data and delete those N, the loop increment step of it++ increments from a now-non-existent element to it's possibly-also-non-existent next element.

Since you're always looking at the first element, your outer loop doesn't need to loop over the elements in mapface, and since you always delete something, can be simplified to while (mapface.size() > 0) {...}.

At lines 27 and 28, it might be more readable to define the face object first, add the AdjacentCells to it, then push it onto the array:

...
Face face(points[ip1], points[ip2]);
face.pushBackAdjCells(ip3);
faces.push_back(face);
...

though I don't think there's anything technically wrong with what you have now.

Try that much, and get back to us?

raptr_dflo 48 Posting Pro

It looks to me like your output so far is correct. The "map" type isn't going to help you with your task, it just provides a space-efficient way of storing an indexed list of objects. Instead, you will want to traverse the tree structure you've built up. Specifically, for parents to have lower ids than their children, you will probably want to use a pre-order traversal of the tree: visit and handle both parent nodes before the individual, recursively. The simplest thing may be to fix the ID of a node and assign it into a new map, both at the same time, then delete the old map when you're finished.

raptr_dflo 48 Posting Pro

As has been discussed in many other threads here, "cin >>" doesn't remove the end-of-line from the stream after you read in the zero or one. So I'm thinking the getline() at line 21 gets the now-empty line and writes it to the file, rather than waiting for a new line of input.

Instead of cin >> n1; at line 16, try:

#include <sstream>
...
string line;
getline(cin, line);
istringstream is_strm(line);
is_strm >> n1;
raptr_dflo 48 Posting Pro

Cool! If/when you're all set, pease mark this thread as "Solved". :)

raptr_dflo 48 Posting Pro

Right near the bottom, you're looping for 5 seconds, but do you have 5 seconds worth of audio in your .wav file to read in? Probably, it's only 5 seconds....

Also, from your earlier question, you're still reading audio data from stdin ... how are you getting the data out of the .wav file? It's not just raw audio samples (see the previous comment), so you can't do cat sound.wav | my_sound_player.exe . Look up how to read data from a .wav file (or find and use an existing library).

raptr_dflo 48 Posting Pro

What happens if you input -6? It looks to me as though your program will tell me it's odd.

Try thinking through your problem out loud. If you can tell yourself logically how it should get to the answer, you should be able to program it correctly.

For starters:
"If my number is positive, i can keep subtracting 2 from it without changing the answer, and will eventually get to 0 (if it was 2, 4, 6, ...) or -1 (if it was 1, 3, 5, ...)."

Now include negative numbers as well. Good luck!

raptr_dflo 48 Posting Pro

As I suggested previously, feel free to remove the "const" wherever you have "const char *" in your code ... it adds extra checking for "correctness", but isn't strictly necessary, and it's wreaking havoc with your use of the C functions from stdlib.h.

As WaltP pointed out, you can't (usefully) change the declarations in the standard headers: those tell you what the default libraries are expecting to receive so that you can compile against them -- think of them as read-only, and provide what they indicate. In this case, atol() doesn't take single characters, it takes C-style strings (arrays of characters with terminating '\0' characters. A quick-and-dirty approach is

char n1_str[2];
n1_str[0] = n1;
n1_str[1] = '\0';
int n1_val = atol(n1_str);

but as I said before, using single characters for n1, n2, n3 means you can't use multi-digit numbers like 10 or 22.

I'm going to go way out on a limb here, and suggest that if you can't fix errors that say a given function expected a "char **" instead of a "const char **" and/or don't even understand what those errors mean, then you're in way over your head here. In answer to your earlier question to the effect of "why can't C++ just handle the strings" ... it can -- it's a process called parsing, and it's what we're working on here. It's a pain in the ass, and the code I've provided to date probably isn't 100% correct yet, but since we can't …

raptr_dflo 48 Posting Pro

Well, despite my best efforts, I can't yet read minds. Post up the code you have at this point, and I'll at least try to figure out why it's crashing. And we'll see where to go next.

raptr_dflo 48 Posting Pro

Hey thecoolman5,
I have cygwin and mingw32 installed on the machine, but unfortunately it's a 64-bit Win7 box, and for whatever reason, the mingw version of g++ is really unhappy in that environment. I've been meaning to fix it forever, but my actual "work" is purely in Python now, so it's not a job requirement to get to it. ;)

MAX_OPERANDS was for you to define, you clearly know how (?) from your previous code. True and False are the Python versions, sorry, C++ uses true and false (lower case) ... the dangers of working in multiple languages! You can remove the "const" from next_ptr at line 25. Since I'm not changing the string, I think declaring it const is the "correct" thing to do, but the declaration of strtod doesn't want it. It might also depend on whether you're hitting the strtod() from stdlib.h (which is C, and predates "const"-ness) or std::strtod() from cstdlib. And probably more. Anyway, my point was to illustrate how you could work with more complex structures and arrays to simplify your code and make it more readable and maintainable.

Anyway, you don't want to "redeclare" your variables (presumably within an enclosing block, otherwise you'd get a compiler error). What you're actually doing in that case is creating a new variable (with its own memory) with the same name as the previously existing one(s), thus "masking" the previous ones (and making them difficult or impossible to access within that block). The extremely …

raptr_dflo 48 Posting Pro

Consider using arrays, to reduce the amount of repeated and nearly identical code:

double n[3], ans;
char operators[2];
int n_index;

cout << "equation: ";
cin >> n[0] >> operators[0] >> n[1] >> operators[1] >> n[2];

cout << "which number do you want to replace with a variable (starting with 1)? "
cin >> v_index;
v_index -= 1;  // index starts from zero

int index_1, index_2;
bool reverse_operators = False;

// assuming the second operator is the '='
if (v_index == 0) {
    index_1 = 2;
    index_2 = 1;
    reverse_operators = True;
}
else if (v_index == 1) {
    index_1 = 2;
    index_2 = 0;
    reverse_operators = True;
}
else {
    index_1 = 0;
    index_2 = 1;
}

if (operators[0] == '+') {
    if (reverse_operators)
        ans = n[index_1] - n[index_2];
    else
        ans = n[index_1] + n[index_2];
}
else if (...

Now to be more generally useful, you'd like to be able to detect variables (and eventually function names like 'sqrt'), and it would be good to be able to find '=' signs as well.

The std::string class is a good place to start, and cstdlib functions skip over whitespace, so you can just read in a whole line once, and then see what you have.

// TODO: make tokens[] a dynamically growable array
std:string line;

cout << "Enter equation: ";
getline(cin, line);

const char *line_chars = line.c_str();
const char *line_ptr = line_chars;

// assuming the only options are numbers, variables, and the operators +-*/=
// and that they …
raptr_dflo 48 Posting Pro

Oh, and if a DACT string is always 142 bytes, and DACT_LENGTH = 142, then if you send the extra null byte (in addition to the 142), then you need to make sure you receive it as well, but I don't think that's your problem or your 2nd received DACT would be corrupted because it's off by one byte, and so on.

Your dact_line string maintains a trailing null byte for you, so you don't have to worry about parsing some infinite string into a DACT (as long as you're appending only the recsize bytes from the buffer onto the end).

raptr_dflo 48 Posting Pro

We humorously call bugs that disappear when you add debugging "Heisenbugs", after the Heisenberg Uncertainty Principle (that observing a quantum event affects the outcome of the event). But the truth is, it's usually a very hard-to-find memory error, often a buffer-overrun of some sort, and not really as "unpredictable" as we'd like to believe....

I don't think you're ever copying too much data (e.g., the start of the next DACT) into the buffer, but your code might be a little clearer if re-organized as follows:

DACT dact;
int recsize, total_rec_size, to_receive;
while (True) {
    // 1. reset values
    total_rec_size = 0;
    dact_line.clear();
    // 2. read entire DACT buffer
    while (total_rec_size < DACT_LENGTH) {
        to_receive = DACT_LENGTH - total_rec_size;
        recsize = recv(connectFd, (void *) buffer, to_receive, 0);
        if (recsize <= 0) {
            // connection closed (0) or error (-1)
            break;
        }
        dact_line.append(buffer, recsize);
        total_rec_size += recsize;
    }
    if (total_rec_size < DACT_LENGTH) {
        // broke out of above loop before done, break out of outer one now
        break;
    }
    // 3. convert to structure
    str2dact(&dact, dact_line);
    receivedDacts.push_back(dact);
}

I don't think I've changed anything important, but eliminated a recv() call and an append() call (from the source code, not the execution ... each will still be called the same number of times for the same conditions, just all inside the loop).

raptr_dflo 48 Posting Pro

C++ or otherwise, are you familiar with the following concepts?
+ Linked lists
+ Stack data structure
+ Binary tree structure
+ Parsing tokens from a string
If not, you may be taking on an effort that's more complex than you're ready for.

The basic problem is: for an arbitrary expression entered by a user, you need to tokenize it (recognize what's a number, what's an operator, what's a function, and what's a grouping-via-parentheses), build a parse-tree (creates a structure which indicates which operations should be performed in which order ... and in the process determine whether the input makes sense and generate an error if it doesn't), and then evaluate the parse-tree to arrive at an answer.

This really is the same basic functionality as writing a computer-language interpreter (although in this more limited case, only the part that deals with arithmetic). Once you understand that what you're trying to do is (1) define a language [basic arithmetic and some simple functions] and (2) write an interpreter for that language, you can then decide if you're ready to undertake that level of effort.

I'm not going to provide you any additional direction at this point, because I don't have the extra time right now to start writing my own arithmetic interpreter! Best wishes!

raptr_dflo 48 Posting Pro

I'll save you the typing: http://www.google.com/search?q=recursive+descent+parser Feel free to ask if there's a concept you don't understand (after your own further investigation), or once you have more code to look at.

raptr_dflo 48 Posting Pro

I think he was at least partly busting your chops. There have been at least two other threads on the exact same subject in the past few days, are you guys all in the same class? Try this one: http://www.daniweb.com/software-development/cpp/threads/365271

raptr_dflo 48 Posting Pro

Since your sender-code reads the DACT objects out of a file, and then sends them to the receiver, you should be able to save received DACT objects into a new file (whenever you receive a complete one). When you finish, you can just 'diff' the two files, and that will at least show you which lines are getting duplicated. If you also print a notice when you receive a partial DACT string, before you loop back to get more input, that might shed some more light on what's going wrong and where.