phorce 131 Posting Whiz in Training Featured Poster

No.. A 2D array will still allocate 1D block of memory.. It's just how you access this.. For example:

    rows = 13;
    cols = 10;
    int* values;
    values = new int[rows*cols];

    for(unsigned i=0; (i < rows); i++)
    {
        for(unsigned j=0; (j < cols); j++)
        {
            values[i*cols+j] = 0.0;
        }
    }

We are still using a 1D block of memory, however, accessing this 1D of memory as a 2D (array).. Does this make sense/

phorce 131 Posting Whiz in Training Featured Poster

Can I just ask.. Why are you reading the words in twice? This cannot be right.. Could you not just read the words into an array, and then perform the word count / unique word count in separate functions?

phorce 131 Posting Whiz in Training Featured Poster

$cust_id = $tmp[4]; will always be at position 4.

What is the exact problem you're having?

phorce 131 Posting Whiz in Training Featured Poster

I'm sure many will agree, facial recognition is a hard task to acomplish; particularly in C++ as this (without any libraries) would require you to build such from the ground upwards in order to give come close to an expected outcome, which is why most researchers use Matlab etc..

That being said, there is a very good, and useful library ouut there called openCV: Here which will give you the toolset in order to complete this. The good thing about openCV is it is open source, and, thus means that there are 100's of documentation centered on Facial Recognition and image recognition etc.. Take a look at this: Here as an example.

Hope this helps

iamthwee commented: Yup +14
phorce 131 Posting Whiz in Training Featured Poster

For a start off: This really isn't a PHP related question since it has more to do with CSS. I don't know why you're using PHP, unless, you are generating or rendering the image.

Post some code, otherwise, we cannot help.

phorce 131 Posting Whiz in Training Featured Poster

Please mark this thread as solved and give rep to who you think helped you.

phorce 131 Posting Whiz in Training Featured Poster

if ($return === false) {

Has to be:

if ($return == false) {

What you are saying in your first argument is that: $return is the type of false Attempt to use just == and post what happens. I believe this is the case for here.

phorce 131 Posting Whiz in Training Featured Poster

@mmcdonald

How would this work:

<?php echo number_format($row_total['sub_total'], 2, '.', '')]; ?>

Where did the last ] come from?

It should be:

<?php echo number_format($row_total['sub_total'], 2, '.', ''); ?>

Would work, I guess!

=)

phorce 131 Posting Whiz in Training Featured Poster

I'm no expert on this function, but shouldn't it be:

echo number_format((int)$row_total, 2,'.','');

Since you are denoting an array $row_total[blah];

phorce 131 Posting Whiz in Training Featured Poster

What is the error? Please post the error what you're having otherwise we cannot help.

phorce 131 Posting Whiz in Training Featured Poster

I have no idea what you are trying to do here.

You have two 1D arrays, do you want to merge these arrays so they become a 2D array?

phorce 131 Posting Whiz in Training Featured Poster

What don't you understand?

You are creating a pointer to an array and trying to output the size, this is not allowed sice the compiler does not know what the pointer is pointing to.

In your cose, you woud not not need a pointer, it would just work lik this:

#include<iostream>

using namespace std;
int p[10][20];//
int main()
{
    cout<<sizeof(p)/sizeof(int)<<endl;
    //getch();
    return 0;
} //output: 200
phorce 131 Posting Whiz in Training Featured Poster

I'm having the same problem!! If I upload two images, only one will upload..

phorce 131 Posting Whiz in Training Featured Poster

So in the normalize_abs_value function, I would take the value of samples[i] and then multiply by 2 to the power of 15?

phorce 131 Posting Whiz in Training Featured Poster

But in the line:

float norm = ABS(samples[i] / 32768); // NOT short.MaxValue

It tells me not to use short.MaxValue so I assumed that numeric_limits::max will do the same as this?

phorce 131 Posting Whiz in Training Featured Poster

What error do you get when you put:

$result = mysql_query("SELECT cat.Name, sub.Name FROM sub_categories sub, categories cat WHERE cat.Id = sub.CategoryId AND sub.id=$categoryId") or die($myQuery."<br/><br/>".mysql_error());

??

phorce 131 Posting Whiz in Training Featured Poster

Should this:

$result = mysql_query("SELECT cat.Name, sub.Name FROM sub_categories sub, categories cat WHERE cat.Id = sub.CategoryId AND sub.id=$categoryId;");

Be:

$result = mysql_query("SELECT cat.Name, sub.Name FROM sub_categories sub, categories cat WHERE cat.Id = sub.CategoryId AND sub.id=$categoryId");

?

phorce 131 Posting Whiz in Training Featured Poster

I believe there is a function which returns the max value for a double, however, I do not need this. I'm converting the following function:

public void StaticCompress(short[] samples, float param)
{
    for (int i = 0; i < samples.Length; i++)
    {
        int sign = (samples[i] < 0) ? -1 : 1;
        float norm = ABS(samples[i] / 32768); // NOT short.MaxValue
        norm = 1.0 - POW(1.0 - norm, param);
        samples[i] = 32768 * norm * sign;
    }
}

But instead of using shorts I pass in a double array. Anyone have any suggestions?

phorce 131 Posting Whiz in Training Featured Poster

EDIT:

It's because you're trying to regiester a session. You should probably just use:

if(!isset($_SESSION['email']))
{
   // redirect
}

OR

if(!session_register($email)){ // error on line 3

Bleh. Please tell us what the purpose of 'login_success.php' is?

phorce 131 Posting Whiz in Training Featured Poster

No problem :) Don't forget to leave people rep

phorce 131 Posting Whiz in Training Featured Poster

After Message is displayed "Database Successfully updated!" for it to return back to the html form it was originally on?

Suppose you could use: header("Location: form.html");

Also a tutorial somewhere on how to handle if Email and Code is UNIQUE and same values have already been entered it displays an error message specific to Email or Code?

You should be able to find these, doing a DaniWeb search, and/or a good search.. But I'll write some functions to get you started..

    function checkEmail($email1, $email2) {

        return (bool) ($email1 == $email2) ? 'true' : 'false';
    }   

    function checkRex($email)
    {
        return (bool) filter_var($email, FILTER_VALIDATE_EMAIL);
    }

We can use these as follows:

// assume you've asked the person to confirm their email address:

$Email;
$Emailconfirm;

if(!checkEmail($Email, $Emailconfirm){
 die("Your emails do not match");
}

// function to check if email is valid

if(!checkRex($Email))
{
   die("Your email is not valid");
}

Or to check if the email already exists:

    function checkExists($email)
    {
        // sql details      
        $query = "SELECT email FROM users WHERE email='$email'";
        $result = mysql_query($query);
        if(mysql_affected_rows($result) == 1)
        {
            return (bool) true;
        }else{
            return (bool) false;
        }
    }

Hope this helps

phorce 131 Posting Whiz in Training Featured Poster

First off, it's wrong.

It should be:

$id = isset($Telephone) ? trim($Telephone) : " ";

The expression is a Ternary logic operator and it will assign $id to whatever is set. So it's just like doing the following:

if(isset($Telephone)
{
   $id = $Telephone;
}else{
  $id = "";
}

Hope this helps

EDIT:

So in theory what we do is:

1) Initialise a variable "$id" to hold the value passed through $_POST['Telephone'];

2) Using the tinary operator, assign $id with a value based on some logic: `if(isset($Telephone) // is there a vaue ? // yes there is $Telephone) // return $Telephone : // no there isn't a value, so 'id' gets stored as null || empty

phorce 131 Posting Whiz in Training Featured Poster

It looks like it doesn't know what $Telephone = $_POST['Telephone']; is since you are not posting Telephone you are posting: Phone so do this:

$Telephone = $_POST['Telephone'];
    $id=isset($_POST['$Telephone']) ? trim($_POST["$Telephone"]) : "";

// has to be :

$Telephone = $_POST['Phone'];
    $id=isset($Telephone) ? trim($Telephone) : "";

This should work

phorce 131 Posting Whiz in Training Featured Poster

My browser does not seem to be making new tabs.. Please see

phorce 131 Posting Whiz in Training Featured Poster

To answer your questions:

With your example - I dont understand the unset($username); // not needed.

Would that remove the username var?

No, since we would store the username in validated_username after we have done the validation.

2) You could use the following:

<?php

    function validateString($str) {

        return $newString = preg_replace('/[^a-z0-9]/i', '', $str);
    }

    $username = "J/A/M/E/S_B/O-N-D";

    echo validateString($username);

    // output: JAMESBOND

The problem with this is: Let's suppose I have a database of usernames, and, each username has to be unique. If the username: "Jamesbond" is taken, and, therefore, someone enters "james_bond" then this function will remove the "_" and if the right measures aren't in place will create another username with this. You could, use the following function which will remove all of the special characters AND then check it against the database.

Protect against xss and sql injecting attacks.

The function ^^ does a pretty good job when it comes to this, of course, it does all depend on how you are handing your SQL queries.. BUT, this function does strip the string against any HTML/JS which could potentially cause XSS.

Does this help?

phorce 131 Posting Whiz in Training Featured Poster

For that, you will need to use regex, and somehow remove the the characters from the username. Or, don't allow for such characters to be entered in the first place.

This function you want limits the chances of XSS by stripping the HTML/JS code from the string.

What is it you're trying to do exactly?

phorce 131 Posting Whiz in Training Featured Poster

Yes.. Since in the example I gave you: var_dump($str2); will print out the result from the function.

If for example, I did this:

    $str = (string) "<script> alert('sff'); </script>";
    $str2 = ft_xss($str);

    echo $str2;

The output would show the "<script>...</script>" because that's what its' been told to do.

So, in your case it would be this:

// Let's look at an example:

$username = $_POST['username']; // posted from a text field.

$validated_username = ft_xss($username);

unset($username); // not needed.

Does this make sense?

phorce 131 Posting Whiz in Training Featured Poster

First off, that is really badly laid out.. What the hell is going on there?

Second of all: What it is you're trying to do?

I.e. add in the error validation, When the form is submitted, a new list of Country names is populating the dropdown box. I don't understand :(

phorce 131 Posting Whiz in Training Featured Poster

No, this is a class. Classes are different, you have to create an object of this class in order to call this method. Are you wanting to use multiple methods from this class? If not, here, try this:

<?php

function ft_xss($str, $charset = 'ISO-8859-1') {
    /*
    * Remove Null Characters
    *
    * This prevents sandwiching null characters
    * between ascii characters, like Java\0script.
    *
    */
    $str = preg_replace('/\0+/', '', $str);
    $str = preg_replace('/(\\\\0)+/', '', $str);

    /*
    * Validate standard character entities
    *
    * Add a semicolon if missing.  We do this to enable
    * the conversion of entities to ASCII later.
    *
    */
    $str = preg_replace('#(&\#*\w+)[\x00-\x20]+;#u',"\\1;",$str);

    /*
    * Validate UTF16 two byte encoding (x00)
    *
    * Just as above, adds a semicolon if missing.
    *
    */
    $str = preg_replace('#(&\#x*)([0-9A-F]+);*#iu',"\\1\\2;",$str);

    /*
    * URL Decode
    *
    * Just in case stuff like this is submitted:
    *
    * <a href="http://%77%77%77%2E%67%6F%6F%67%6C%65%2E%63%6F%6D">Google</a>
    *
    * Note: Normally urldecode() would be easier but it removes plus signs
    *
    */  
    $str = preg_replace("/%u0([a-z0-9]{3})/i", "&#x\\1;", $str);
    $str = preg_replace("/%([a-z0-9]{2})/i", "&#x\\1;", $str);      

    /*
    * Convert character entities to ASCII
    *
    * This permits our tests below to work reliably.
    * We only convert entities that are within tags since
    * these are the ones that will pose security problems.
    *
    */
    if (preg_match_all("/<(.+?)>/si", $str, $matches)) {     
        for ($i = 0; $i < count($matches['0']); $i++) {
            $str = str_replace($matches['1'][$i],
                html_entity_decode($matches['1'][$i], ENT_COMPAT, $charset), $str);
        }
    }

    /*
    * Convert all tabs to spaces
    *
    * This prevents strings like this: …
phorce 131 Posting Whiz in Training Featured Poster

Do you have your own class?

If not, remove the public from it and just do the following:

ft_xss($str)

Where $str is the string you want to pass.

Its difficult to say though, since you've only provided half of the function and therefore cannot determine the return type.

phorce 131 Posting Whiz in Training Featured Poster

You should really use strings for this.

It would therefore be:

std::string v = "blueone";

std::string toFind = "one";

if(v.find(toFind) != string::npos)
{
   std::cout << "Found";

   /* you could then do something like:

   if(toFind[i....] == "one")
   {
       int value = 1; 
   }
   */

}

You'd need to have two seperate arrays, then using recursion so that each element is checked with each of the array values you want to find.

Hope this helps

phorce 131 Posting Whiz in Training Featured Poster

This makes no sense..

What do you mean:

Then convert these strings to there numerical values. 1,2,3,4,5. How would I do this?

Do you mean the the place where they are in the array? i.e "0", "1"....

Or do you mean:

blueone then becomes blue=>one and then from there, store "1" and green=>two etc..?

phorce 131 Posting Whiz in Training Featured Poster

I might be a bit tired, but why does the following not work?

class Signal {

    public:

        Signal() {

        }

    protected:
        std::vector<double> data;

};

class Something : public Signal {

    public:

        Something()
        {
            data.resize(100);
        }

};

class Parser : public Signal {

    public: 

        Parser()  {
            std::cout << this->data.size();
        }

};
int main()
{
    Something w; // resizes vector data to 100

    Parser f; // outputs size
}

Since I call Something which resizes the vector.. But, in Parser I can't seem to access the data member?

Arghh!

The output is 0 -> If, however, I inherit from Something it will work?

phorce 131 Posting Whiz in Training Featured Poster

If this problem has been solved. Could you mark it as solved please?

phorce 131 Posting Whiz in Training Featured Poster

Came up with a solution:

#include <iostream>

using namespace std;

class Parser {

    public:

        Parser() { cout << "Parser constructor "; }
};

class Signal {

    public:
        friend class Parser; 
        Signal() { }

        Signal& Parse() {
            Parser* p = new Parser();
            return *(this);
        }
    protected:

};


int main(int argc, char *argv[]) {

    Signal s = Signal().Parse();
}

Probably not the best implementation, but, hey! If anyone has any more, feel free to post :)

phorce 131 Posting Whiz in Training Featured Poster

I basically have two classes: Signal and Parser they both have differences, however, they each share the data that Signal has.

I want to incorperate Method Chaining into the class, so my classes (at the moment look like the following):

class Signal {

    Signal() { 

    }

    Signal& Parse()
    {
       return *(this);
    }
};

And my other class looks like the following:

class Parse : public Signal {

    Parse() {

    }
};

This will therefore allow me to do the following in main: Signal s = Signal().Parse();

But what I need to do is in the class Signal when Parse is called, initialise a new object of the class Parse so it can do it's "business". The class constructor in Parse will use the data in Signal.

I know this is possible using CRTP, however, using CRTP would require me to have a template method for Signal, and, I cannot have this due to other classes inheirting from Signal.

Anyone know of an alternative to solving such problem?

Thanks

phorce 131 Posting Whiz in Training Featured Poster

@Andy - If we pass by reference, we get the actual memory allocations and not the value. Thus meaning we can ensure speed as well as the fact if the values have to be changed in any way.. Then this will be done in direct memory.

phorce 131 Posting Whiz in Training Featured Poster

You are missing the ; off your function prototypes. The ones you have, should work with your compiler..

You could, however, do the following:

void Scanned(std::ifstream& ifp,int i);

but make sure you include <fstream>

Your struct seems fine, is there a reason why you're not using classes - Just out of interest?

You shouldn't really need the typedef and would be just the following:

struct Checker
{
  int age;
  char name[20];
  int  roll_call;
};

Also, in the following: Checker pass in the arrays as references: int Checker(char *s,char *u)

Hope this helps.

phorce 131 Posting Whiz in Training Featured Poster

university they would briefly cover each of these fields.

This totally depends on the University and/or the choice of course you study. Most are programming based (in the UK) but it's very unlikly (unless you study a Games related course) that they will cover "Graphics Porgramming" however, Web Developer and Mobile Development are becoming more dominant in the market so these would be covered.

So what I'm trying to ask is, would I be at least equally competent to a university graduate?

Universties "teach" you how to research independantly and within a group. I wouldn't go to University and expect them to teach you EVERYTHING there is to know about programming/languages/compilers/operating systems/algorithms etc.. So, it depends on your personal prospective; if you decide not to choose a University course, and gain experience and knowlege then I doubt that will go against you when applying for jobs, since, most graduate jobs these days require experience over a "piece of paper" so it all depends.

With regards to your first post:

code a basic operating system

Why? What would be the point in this? The latter, getting involved with the Linux community and helping developing something - This would be ideal.. Not creating your own operating system.

If I learn several programming langauges, assembly, complier design, software architecture, design patterns, to write clean code, electronics, some common libraries, data structures and algorithms, networking, database managamenet systems, front end …

phorce 131 Posting Whiz in Training Featured Poster

What have you done to understand the problem? Do you expect someone to do your problem? If it's "simple" and "not hard" then surly you would be able to do this yourself?

phorce 131 Posting Whiz in Training Featured Poster

Yes you can do the following. But, your default constructor should be left. Then, you can use method overriding to pass values through.

phorce 131 Posting Whiz in Training Featured Poster

Hey,

So you need to mark this as solved, if your question has been answered. (There should be an option 'mark this thread as solved) and then, at the side of each of the members username, there is an arrow up and down click the up arrow if someone has helped you, or the down arrow if you feel the post is bad or just generally didn't like it.

Hope this helps :)

cambalinho commented: thanks +0
phorce 131 Posting Whiz in Training Featured Poster

I suppose you could do the following:

class Test {

    public:

        Test() {

        }

        Test(std::string val)
        {
            value = val;
        }

        std::string show(){
            return  value;
        }
    protected:

        std::string value;

};
int main(int argc, char *argv[]) {

    std::string vala = "Hello a";
    std::string valb = "Hello b";

    Test a(vala);
    Test b(valb);

    cout << a.show() << endl;
    cout << b.show();
}

What you're asking here is:

test a;
test b;

void a::Show()
{
   cout << "hello a";
}

void b::Show()
{
   cout << "hello b";
}

It is basically saying that there is a class called a and a class called b and these are therefore not obects you would create in main. For example: What if you had an array of objects going from a, b, c.... then would you therefore need to invoke a member class for each object? No, this isn't object oriented programming. You could have classes that call different member functions depending on the object that is called, this, however, is called Polymorphasim.

cambalinho commented: thanks +0
mike_2000_17 commented: Keep it up! +14
phorce 131 Posting Whiz in Training Featured Poster

I believe what you are meaning here is Polymorphism?

Here is an example:

class Base {

    public:

        Base() { }
        virtual std::string speak() { return 0; } 
};

class Dog : public Base {
    public:
    Dog() { }
    std::string speak() {
        return "woof";  
    }
};

class Cat : public Base {
    public:
    Cat() { }

    std::string speak() {
        return "meow";
    }
};
int main(int argc, char *argv[]) {

    Dog d;

    cout << d.speak(); 

    Cat c; 

    cout << c.speak();
}

Depending on which object I define, determines the output and therefore will change.

Also, it is not good standard to have cout << in any class members.

Hope this helps

phorce 131 Posting Whiz in Training Featured Poster

Your default constructor is the definition in which you will initialise your objects from. (in main usually)

Your default constructor looks like the following:

P.S. It is also worth noting that the class name should always be capitialised as this is a good coding practise, so, Book instead of book with that being said, your class should look like the following:

class Book {

    public:
        Book(); // Default constructor 

    private:

        char author, publisher, price ,ibn;
};

You should also make the access specifiers clear, i.e. public, private, protected

Hope this helps.

phorce 131 Posting Whiz in Training Featured Poster

Are you allowed to use vectors? If so, this is a way to think of it. In no means, is this the final solution. Just a way for you to think about it. I would use a vector to store the values in, then, create another vector to store the even numbers in and finally calculating the sum of all the values inside the Even vector. Here's an example:

#include <iostream>     // std::cout
#include <algorithm>    // std::count_if
#include <vector>       // std::vector
#include <numeric>
using namespace std;

bool IsOdd (int i) { return ((i%2)==1); }

int main()
{
    int number1;
    int number2;

    int summation = 0;
    std::vector<int> values(number2); 
    std::vector<int> evenValues;

    cout << "Please enter your first number: ";
    cin >> number1;

    cout << "Please enter your second number: ";
    cin >> number2;

    for(unsigned i=number1; (i < number2 + 1); i++)
    {
        values[i] = i;

    }
    // Count all the variables that are even

    for(unsigned j=0; (j < number2+1); j++)
    {
        if(!IsOdd(values[j]))
        {
            evenValues.push_back(values[j]);
        }
    }

    summation = std::accumulate(evenValues.begin(), evenValues.end(), 0);

    cout << summation << endl;


}
phorce 131 Posting Whiz in Training Featured Poster

Where did this come from? I have not seen coding like this, at all.

phorce 131 Posting Whiz in Training Featured Poster

If you have a key pair value, then surely the best possible structure to use would be a hash table over a binary tree? Give some sample output of the file, please.

phorce 131 Posting Whiz in Training Featured Poster

Are you for real? DO YOUR WORK!!

Click Here

For the onversion formular, literally will take you 2 seconds to write this.

phorce 131 Posting Whiz in Training Featured Poster

The only reason the US wants to take Military action is to nuke the hell out of Syria, thus killing innocent people and all to show Iran and the rest of the world what such a powerful country the US is.

The security council and the UN should come up with a peaceful resolution without getting involved.