Insensus 52 Junior Poster
bool pComp(int* a, int* b) { return *a < *b; }

vector<int*> pVec;
std::sort(pVec.begin(),pVec.end(), pComp);
Jsplinter commented: thank you +2
Insensus 52 Junior Poster

A quote from the PHP session_destroy manual

session_destroy() destroys all of the data associated with the current session. It does not unset any of the global variables associated with the session, or unset the session cookie. To use the session variables again, session_start() has to be called.

In order to kill the session altogether, like to log the user out, the session id must also be unset. If a cookie is used to propagate the session id (default behavior), then the session cookie must be deleted. setcookie() may be used for that.
Insensus 52 Junior Poster

Are you serious?

Insensus 52 Junior Poster

You're missing a . at line 46.

'"$_POST['fd_period']."'
'".$_POST['fd_period']."'
Insensus 52 Junior Poster

What you have now is:

10 => 0
11 => 1

I suspect you want:

9 => 0
10 => 1

Which I'd do like:

$ASoliderPercent = floor($attackerSoldiers/10);
Insensus 52 Junior Poster

I don't think it doesn't find it but your method of checking whether it has is wrong.
Instead try

if (inFile.is_open())
Insensus 52 Junior Poster

Ok I'm sorry I missed that.
But there's still an error in your MySQL query and you would've known had you executed it like this:

$result = mysql_query($query1) or die(mysql_error());

The problem is that since both your datatable and datatable2 contain a field numid, the WHERE numid='0010' is ambiguous as you don't specify if it's the numid from the first or second table.
Even though your query suggests that the results wouldn't differ I think this is the problem.

Insensus 52 Junior Poster

You can't do that because 5.0 is stored as 5.
There is nothing stored about how many insignificant zeroes you entered in your code.

Insensus 52 Junior Poster

This means your mysql_query returns a false because there's an error in your query.

Which is the result of line 11 because your query will look like:
select * FROM datatable LEFT JOIN datatable2 ON datatable.numid=datatable2.numid WHERE numid='$numid' AND
There is nothing following the AND which produces an error.

Insensus 52 Junior Poster

Why not use my solution?
It guarantees no two equal randoms and doesn't require database queries.

Insensus 52 Junior Poster
$rands = range(300, 10000);
shuffle($rands);

$random1 = array_pop($rands);
$random2 = array_pop($rands);
$random3 = array_pop($rands);
...
diafol commented: I like that :) +13
Insensus 52 Junior Poster

This suggests there is an error in your SQL-query on line 5.

Replace line 5 with:

$mark = mysql_query("select * from product order by product_id DESC") or die(mysql_error());

and see what you get.

Insensus 52 Junior Poster

Ok I've think I figured out why your code doesn't work, but I don't think there's a way to do it exactly like you want to.

The problem is this:
The return type of union_set is the same type as given for the 5th argument, the OutputIterator.
In your case this means union_set returns a back_inserter_iterator<vector<int>> yet you want to assign this to a vector<int>::iterator.

The easiest way to fix this is by indeed removing the it = and simply using unionsetv.end() whenever you would've wanted to use it.

Insensus 52 Junior Poster

Quote from cplusplus.com
For the function to yield the expected result, the elements in the ranges shall be already ordered according to the same strict weak ordering criterion (operator< or comp).

Insensus 52 Junior Poster

Did you press the AJAX Examples link on the left?

Honestly, I think that site is all you'll ever need.
It's all I ever needed anyway.

Insensus 52 Junior Poster
Insensus 52 Junior Poster

I don't know what the purpose of this code is but it looks like they want the following set of selection rules:
sizeof(T1) > sizeof(T2): ResultT = T1
sizeof(T1) = sizeof(T2): ResultT = void
sizeof(T1) < sizeof(T2): ResultT = T2

With the alternative you suggested the selection rules would be:
sizeof(T1) > sizeof(T2): ResultT = T1
sizeof(T1) <= sizeof(T2): ResultT = T2

Insensus 52 Junior Poster
$rands = range(1,40);
shuffle($rands);

for ($i=0; $i<$numeroDeobjetos; $i++) {
  $usada[$rands[$i]] = true;
}
Insensus 52 Junior Poster

Line 139.

denominator /= b;

should of course be

denominator /= a;
Insensus 52 Junior Poster

Because the \ is the character used to escape things like quotes, it's not appropriate to use it on its own.

Use

std::cout << " \\ ";

instead.

Insensus 52 Junior Poster
bool playAgain = true;
cin >> playAgain;
while( (playAgain == 'Y' || playAgain == 'y' ));

Enough of a hint? :)

Insensus 52 Junior Poster

Line 56.

int d = rhs.denominator

This misses an ending semicolon.


Line 47:
When adding two variables of the type Rational like:

f1 + f2;

What happens function-call wise is:

f1.operator+(f2);

so Rational rhs is the Rational that is added to the Rational with which we start.

Insensus 52 Junior Poster

Again you are trying to get the value you want from the variable $data which does not contain the result of the query.

But

$query = mysql_query($data) or die("Couldn't execute query. ". mysql_error());
$row = mysql_fetch_array($query);
echo $row['ID'];

should work.

What this does is:
mysql_query: execute the given query on the database; returns a MySQL resource variable from which you can extract the actual result of the query.

mysql_fetch_array: read the next row (or false if there aren't any left) from the query-result given as an argument. This has to be a MySQL resource like the above function returns.
This returns an array containing the fields of the result for one row and since you'll never get more than one row you only have to call it once.

Now the $row should contain what you are looking for.

Insensus 52 Junior Poster

The query as I posted should be fine on itself, but in the code in your last post no query ever gets executed.

All you are doing right now is making a string $data which contains the query you want to send, and setting $id to the int-value of an undefined variable ($row doesn't exist in your code) which comes down to $id = 0.
So when echo-ing $data[$id] you should expect $data[0] to be echo'd which is the first character of the string $data which is an S.

Try understanding what this page reads under 2. Procedural style. It's about how to execute query's.

Insensus 52 Junior Poster

That's because HTML automatically reduces subsequent horizontal spacing to one space only.
If you want more you'll have to use the &nbsp; HTML-entity.

Insensus 52 Junior Poster

You can't include array variables in double-quote strings like that, this has to be done either of two ways:

// Connect to the database
    $dbc = mysqli_connect("localhost", "xxxxxxx", "xxxxxxxxx", "xxxxxxx");
	$data = "SELECT ID FROM user_registration WHERE username = '" .$_SESSION['username']. "'";
	$query = mysql_query($data) or die("Couldn't execute query. ". mysql_error());
// Connect to the database
    $dbc = mysqli_connect("localhost", "xxxxxxx", "xxxxxxxxx", "xxxxxxx");
	$data = "SELECT ID FROM user_registration WHERE username = '{$_SESSION['username']}'";
	$query = mysql_query($data) or die("Couldn't execute query. ". mysql_error());

And don't forget to escape them first of course.

Insensus 52 Junior Poster

DeIntegro,

The reason you're only getting one row is because you're querying for one row. You need to query an array of rows.

$row = mysql_fetch_[b]row[/b]($result);

should be

$row = mysql_fetch_[b]array[/b]($result);

This is not true.
Both functions fetch one row from the query and store it in an array.
The only difference between them is how the array in which the row is stored is constructed:
mysql_fetch_row returns an enumerated array (eg. {[0] => a, [1] => b})
mysql_fetch_assoc returns an associative array (eg. {[x] => a, [y] => b})
mysql_fetch_array returns an array containing both of these (eg. {[0] => a, [x] => a, [1] => b, [y] => b}).

To get multiple rows from your query simply call mysql_fetch_array/assoc/row again and again until it returns false:

while($row = mysql_fetch_array($sql)){
    // Do something with the row
}
diafol commented: Nice explanation +13
Insensus 52 Junior Poster

Yes the line numbering is correct so the question is, why did you put a --> at the end of line 36? (And also 37, 38, 39)

Maybe you were trying to comment out those lines? Note that what you've placed are only HTML comments and since PHP executes before anything is done with the HTML, PHP sees a --> in it's code and that doesn't really make sense.

Insensus 52 Junior Poster

The first attempt doesn't work because if it WOULD work, you could never write the word IPADDRESS in a string without having it replaced by it's definition.
What might work but of which I'm not sure is using {IPADDRESS} instead of just IPADDRESS.

And in the second attempt you didn't get the quotes at the end right.

$update = mysql_query("UPDATE login_errors SET tries = '$addtry' WHERE ip_address = '".IPADDRESS."' ") or die(mysql_error());

1. The :: means that you're accessing the member function of a class definition without an initialized class (so this is not definied)

2. I've never seen session_set_save_handler before but from what I just read it appears that it enables you to define your own way of saving a user's session data, so you could save it in a database but not on the client's machine.

Insensus 52 Junior Poster

If you look at this page http://www.cplusplus.com/reference/algorithm/find/ you'll see that find() requires the == operator to be defined on your class, and it's not.

Something like this probably:

bool A :: operator ==(const A &t) const
{
	return ((x == t.x) && (strcmp(name, t.name) == 0));
}

On a side note, why did you define putData() as a member-function of A even though it doesn't do anything with the A it's called from?

And why does getData() take an argument which it doesn't use?

Insensus 52 Junior Poster
output.open("TEMPS.DAT", ios::in);
output << temp[counter1] << endl;

Do not make sense as you are trying to write to an in-stream.

This should be what you're looking for:

output >> temp[counter1];
Insensus 52 Junior Poster

The easiest way to see if the derivative changes sign when considering time derivatives would of course be to see if the difference between the last and 2nd to last Z changes sign.
This would mean something like if((deltaZ[lcv] - deltaZ[lcv - 1]) * (deltaZ[lcv - 1] - deltaZ[lcv - 2]) < 0). (Note that this fails when Z is identical for subsequent values of t)
You don't even need to compute the derivative for each set of values.

#include<iostream.h>
#include<fstream.h>
#include<string>
#include <C:\dislin\dislin.h>

 main () {
    ifstream fin ("prog10.text");
    float x[10000], y[10000], T[10000], Z[10000], derivative[10000];
    float direction = 0;
    int nPoints;
    int lcv = 0;
    cout<< "The velocity changes direction at: " << endl;
    
    for (lcv  = 0; !fin.eof(); lcv++)
    { 
        fin >> T[lcv] >> Z[lcv];
        
        // Make sure two subsequent identical Z's don't mess everything up
        // by keeping track of the latest non-zero direction
        if (lcv > 0 && Z[lcv] != Z[lcv - 1])
        {
            // Check if the direction changes sign for this (T,Z)
            if (direction * (Z[lcv] - Z[lcv - 1]) < 0)
            {
                // Got one
            }

            direction = Z[lcv] - Z[lcv - 1];
        }
    }
}
Insensus 52 Junior Poster

Quote from cpp reference:

'Allocates a block of size bytes of memory, returning a pointer to the beginning of the block.

The content of the newly allocated block of memory is not initialized, remaining with indeterminate values.'

Insensus 52 Junior Poster

Obvious question: do you have a mail server running?

Insensus 52 Junior Poster
$result = str_replace ("--","-",$string);

Should remove all
if there's 3 in a row: ---
It would find the first two - and replace with one: [-]-
leaving -- which is then replaced by -

Neither has the desired behaviour.
str_replace doesn't rescan already replaced input and so --- will be matched as -, replaced by [-]-. It will not reinterpret the already replaced [-]- as .


Try this instead

preg_replace("/[-]+/", "-", $in);

This will perform greedy matches by default, matching as many consecutive -'s as it can find and replacing the whole with only one -.

Insensus 52 Junior Poster

Do you mean that this effect has to happen in real time or are you trying to 'render' the images with GD?
Because if you're aiming for real time, GD wouldn't be my tool of choice since you'd have to use for instance AJAX to get every next image from a PHP script.
If real time is what you want I suggest you take a look at jQuery and the dozens of freely available scripts made with it.

Insensus 52 Junior Poster

You've misplaced the parenthesis in this line:

if(strcmp($line,$name == 0)) {

Should of course be:

if(strcmp($line,$name) == 0) {
Insensus 52 Junior Poster

it depends on your application.How you going to iterate/search with the data.
if you searching using a key value , I recommend you to use a hash-map.
other than vectors there are other data structures in STD.

Linked Lists - Does not provide random access, but faster delete and insert.
Vectors - Provides fast random access,but the worst case complexity of a
inserting or deleting a element is worse.
Tree based map- Provides Log(n) worst case complexity when searching.


Each and every data-structure have it's advantages and disadvantages.
You better analyze your input queries. Then you can definitely have an idea
about the following two.
1. what field should I use as a key.
2. what type of data-structure I should use? std::vector , std::list , ... etc.

I have done a part of my sem4 project using std::vector, but it requires a random
access , search quries takes hell of a time to complete,killing all the applications
responsiveness.

Thanks for showing interest in such a big post.


I'll try to explain a little more carefully what I want to do with the stored data:

» The stored data doesn't have to be modified in any way.
» Once a response has been received and parsed I want to return an object from which it's intuitive to access the stored values. Here's two examples:

<array>
   <data>
      <value><i4>12</i4></value>
      <value><string>Egypt</string></value>
      <value><boolean>0</boolean></value>
      <value><i4>-31</i4></value>
      </data> …
Insensus 52 Junior Poster

Hello there forum,

After a pretty thorough C++ course I've tried my hands at coding an actual project but have stumbled on a pretty big problem and here I am asking for your help.

What I'm trying to make right now is a class which communicates with a gameserver through a slightly modified XML-RPC and the problem arises when trying to handle the incoming responses.
These responses are nicely structured in XML format so getting the actual value isn't too hard but storing it in a more elegant way after receiving the response is.

A response can look like this:

<?xml version="1.0"?>
<methodResponse>
   <params>
      <param>
         <value><string>South Dakota</string></value>
         </param>
      </params>
   </methodResponse>

Where the value can be one of 4 simple values: int, double, string, boolean
or a struct or array like:

Array:

<array>
   <data>
      <value><i4>12</i4></value>
      <value><string>Egypt</string></value>
      <value><boolean>0</boolean></value>
      <value><i4>-31</i4></value>
      </data>
   </array>

Struct:

<struct>
   <member>
      <name>lowerBound</name>
      <value><i4>18</i4></value>
      </member>
   <member>
      <name>upperBound</name>
      <value><i4>139</i4></value>
      </member>
   </struct>

Wherein each <value> can be another array or struct.

Now what I'd like to do is read the complete response, parse it and return an object for which it's easy (intuitive) to retrieve a certain value from the response.

So far the best thing I've come up with it is saving all the actual values (that is int, string, double, boolean) in a vector in the class and returning only the structure which references to the vector. However I haven't been able to think of a proper way …

Insensus 52 Junior Poster

You're missing an ending double-quote here.

$servicesoffered="<br/>"."$edit_servicearea_str<br/>\n$detailedmsg<br/>;
Insensus 52 Junior Poster

I just tried the code like you posted and I can't reproduce your problem apart from a little JPEG-encoding (~1 fluctuation e.g. 255 -> 254).
Maybe your screen is playing tricks on you?

Insensus 52 Junior Poster

It would help if you'd show your code. :)

Insensus 52 Junior Poster
<option value="cashout">Refinance-Cashout</option>
$buysell=="Refinance - Cashout"

That doesn't match.
Should be

$buysell=="cashout"
Insensus 52 Junior Poster

In the first file $cid is never defined.
I think you mean $_POST instead of just $cid?

Insensus 52 Junior Poster

And just because I have it finished now anyway, here is what I just made. :P

template <typename T>
T switchEndian(unsigned char * from)
{
	T tmp = 0;
	for(unsigned idx = 0; idx < sizeof(T); idx++) {
		tmp += (from+(sizeof(T)-idx-1))[0] << idx*8;
	}
	return tmp;
}
long result = switchEndian<long>(&foo[6]);

It might be bad code though so I'm not very skilled.

Insensus 52 Junior Poster

Is reversing the vector an option?
I guess this should work:

reverse(foo.begin(), foo.end());
long some_long = *(long *)&foo[0];
Insensus 52 Junior Poster

I am a 22 year old college gal

I see what you did there.. :P

This is the short solution I came up with, but I wouldn't know if it's valid for your exercise.

#include <iostream>

using namespace std;

int posInteger(int sum){
	int number, revSum = 0;
	
	cout << "Enter Positive Number, 0 to end: ";
	cin >> number;
     
	if (number <= 0)
		return 0;
	else {
		sum += number;
		cout << "Sum: " << sum << endl;
		revSum += posInteger(sum) + number;
		cout << number << " Total: " << revSum << endl; 
	}
	
	return revSum;
}

int main(){
	posInteger(0);
	cin.get();
	return 0;
}

Note that this can also be done by passing the reference of a variable from main along with the function which would store the reverse summation, but I don't know if this has been covered yet. Plus it doesn't really matter. :p

Insensus 52 Junior Poster

That's because an array is nothing but a pointer to the start of a memory block, so

cout << array << endl;

will print the memory address of the start of your array.

To print the whole array you should iterate over the 'rows' (first index) and print each array these rows define.
(Note: this still sends a pointer to the cout but since this is just a char * it will print all the chars in that bit of memory.)

Also, this explanation isn't perfect but it should at least make you see what's happening and why.

Insensus 52 Junior Poster

If your file looks like that, why are you trying to split on "|" which you know isn't in the file at all?

$tmp = explode(" ", $var);

Should be what you want.

Insensus 52 Junior Poster

This simply means that the $var you're trying to split doesn't contain any | at all, therefore the resulting array ($tmp) is only 1 element long and $tmp[1] doesn't exist.