phorce 131 Posting Whiz in Training Featured Poster

What don't you understand? are you allowed to sort using std::sort are you sure that arrays are the best structure for this data?

phorce 131 Posting Whiz in Training Featured Poster

Hello,

ld, but I need to start somewhere and make some visible results on my projects.

Maybe you should assess what your "projects" are and then make the decision on the language to choose?

phorce 131 Posting Whiz in Training Featured Poster

Hey,

Something like this:

#include <iostream>

const std::size_t limit = 10; 

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

    try {

        std::cout << "Please enter a number: ";
        std::cin >> numb; 

        if(numb > limit)
           throw 1;
    }
    catch(...)
    {
        std::cout << "Out of bounds";
    }


}

// input 100
// output: Out of bounds
// input 1
// true 
phorce 131 Posting Whiz in Training Featured Poster

What's the specific errors? I can see a lot of problems within this code, but, I don't have the time to physically sit down and re-write this, sorry.

phorce 131 Posting Whiz in Training Featured Poster

Please mark tis thread as solved, thank you.

phorce 131 Posting Whiz in Training Featured Poster

Are you allowed to use strings? This would be so much simplier if you were. Just copy the char array that you have, into a std::string and the following should work..

#include <iostream>
#include <algorithm> 
#include <ctype.h>

using namespace std;

bool is_space (const char &c) { return isspace(c); } 

int main() {
    // your code goes here

    char myStr[] = "hello my name is";

    std::string blah(myStr);
    //std::cout << myStr << std::endl;

    blah.erase(std::remove_if(blah.begin(), blah.end(), is_space));

    std::cout << blah;
    return 0;
}

^^ Is just an example, where myStr is a char array and blah is the string storing the char array.

Let me know how this works for you :)

phorce 131 Posting Whiz in Training Featured Poster

Just a very quick question.. Why would you need/want to convert this to an .exe - Why not give them the source code?

Have you tried: http://www.pyinstaller.org/ ?

phorce 131 Posting Whiz in Training Featured Poster

What do you mean it doesn't? Could you give an example of the input/output?

If, you mean like: "Hello my name is phoce" would then become "hellomynameisphorce" then you can do: std::remove_if(str.begin(), str.end(), isspace) or str.erase(str.begin(), str.end(), isspace), str.end()); Hope this helps.

phorce 131 Posting Whiz in Training Featured Poster

Hey,
Is there a specific question?

phorce 131 Posting Whiz in Training Featured Poster

echo $obj->setPassword("dsadsadasdas'das"); this is wrong. Yo don't return anything, so don't output this. You're setting, not getting. What seems to be the error?

phorce 131 Posting Whiz in Training Featured Poster

If I'm guessing correctly, this function: public function contact() has to accept paramaters.. Then you could do something like this:

<?php

  if(!isset($_POST['form_submitted']))
  {
       // output the form
  }else{

    $c = new ccontctus(); // constructor 
    $c->contact($_POST['uname'], blah, blah, blah);

Something like this?

phorce 131 Posting Whiz in Training Featured Poster

So.. The use of session_register is depreciated.. Instead, use:

$_SESSION['uname'] = "Phorce"; whereas before I might have used session_register("phorce"); i don't know, I never used that function.

Now, everytime you want to check if the session exisits: if(!isset($_SESSION['uname'])) { // } and to output it: print($_SESSION['uname']); I'm sorry but I don't understand what you find so difficult about it?

phorce 131 Posting Whiz in Training Featured Poster

Why session register?

Why not just: $_SESSION["pw"] = "blah"; and then you can: if(!isset($_SESSION["pw"])) { // }

etc..

phorce 131 Posting Whiz in Training Featured Poster

Do you honestly expect someone to give you an answer based on the attempt that you've done? Seriously.. Do some work and if you get stuck on something in particular then someone will help.

proper technique for opening files

Who has stated a "proper technique" by who's standards?

phorce 131 Posting Whiz in Training Featured Poster

Show what you have done so far / give examples of the data

phorce 131 Posting Whiz in Training Featured Poster

The style and syntax is horribly wrong. You should work on this, here:

Q: Why do you need to include the .cpp to this? It's just.. not needed.

Here's an alternative:

Stuff.h

#include <string>

bool Correct_Parent(std::string x)
{
    int p_Left_Counter  = 0;
    int p_Right_Counter = 0;
    for(unsigned int c = 0; c < x.size(); c++)
    {
        if(x[c] == '(' )
            p_Left_Counter++;
        else
        if(x[c] == ')' )
            p_Right_Counter++;
    }
    if( p_Left_Counter != 0 && p_Right_Counter != 0)
        if(p_Left_Counter == p_Right_Counter)
            return(true);
    return(false);
}

You don't need to request the whole of the std namespace: using namespace std when you are only using a string.. This is bad.

Then your main would be:

main.cpp

#include <iostream>
#include "Stuff.h"

using namespace std; // Do you really need this?

int main()
{
    //...
}

This should work. I'm not at a compiler though, so, I haven't checked.

younes.keraressi commented: yes sorry about syntax, yes i need using namespace std to cin and cout +0
phorce 131 Posting Whiz in Training Featured Poster

I don't know why I'm having such a problem with this, basically, I want to have a Queue that is constantly running during the program called "Worker" this then works, however, every 10 seconds or so.. Another method called "Process" comes in and processes the data. Let's assume the following, data is captured every 10 seconds.. (0, 1, 2, 3, ..... n) and then the "Proces" function receives this, processes the data, ends, and then the "Worker" goes back to work and does their job until the program has ended.

I have the following code:

import multiprocessing as mp
import time

DELAY_SIZE = 10

def Worker(q):
    print "I'm working..."

def Process(q): 
    print "I'm processing.."

queue = mp.Queue(maxsize=DELAY_SIZE)
p = mp.Process(target=Worker, args=(queue,))

p.start()

while True:
  d = queue.get()
  time.sleep(10)
  Process()

In this example, it would look like the following:

I'm working...
I'm working...
I'm working...
...
...
...
I'm working...

I'm processing...
I'm processing...
I'm processing...
...
...

I'm working..
I'm working..

Any ideas?

phorce 131 Posting Whiz in Training Featured Poster

I have two threads, and, I want one thread to run for 10 seconds, and then have this thread stop, whilst another thread executes and then the first thread starts up again; this process is repeated. So e.g.

from threading import Thread 
import sys  
import time

class Worker(Thread):

    Listened = False; 

    def __init__(self):

        while 1:
           if(self.Listened == False):
              time.sleep(0)
           else:
            time.sleep(20)

        for x in range(0, 10):
            print "I'm working"
            self.Listened = True

    class Processor(Thread):
Listened = False;

def __init__(self):
    # this is where I'm confused!!

  Worker().start()
  Processer().start()

(P.S. I have indented correctly, however, posting seems to have messed it up a bit)

Basically, what I want is:

The worker thread works for 10 seconds (or so) and then stops, the "processor" starts up and, once the processor has processed the data from the last run of the "Worker" thread, it then re-starts the "worker" thread up. I don't specifically have to re-start the "worker" thread from that current position, it can start from the beginning.

Does anyone have any ideas?

phorce 131 Posting Whiz in Training Featured Poster

Since you've read the data into an array, you would need to therefore search through the array, over the actua file..

phorce 131 Posting Whiz in Training Featured Poster

Do you already have the robotic arm? You could do this using an Arduino, there are hundreds and hundres of resources out there. GIYF (google is your friend)

phorce 131 Posting Whiz in Training Featured Poster

Why use an array? Since you're just asking for the persons namr, you can do:

#include <string>
#include <iostream>
int main() {

    std::string name; 

    std::cout << "Please enter your name: ";
    std::cin >> name;

    std::cout << "Size: " << name.length();
}
phorce 131 Posting Whiz in Training Featured Poster

Explain what you mean.. It's very unclear

phorce 131 Posting Whiz in Training Featured Poster

This:

void getData (string city[], string country[]), double lat[], double lon[];

Is not valid C++ for a function prototype.

It's hard to say, since you don't give an example of the data contained in the file.. Is this possible to supply?

phorce 131 Posting Whiz in Training Featured Poster

Would it not just be easier to use:

<?php
$email_a = 'joe@example.com';
$email_b = 'bogus';

if (filter_var($email_a, FILTER_VALIDATE_EMAIL)) {
    echo "This ($email_a) email address is considered valid.";
}

PHP already has this built-in!!

But, what you have used is a function, to call this function you would use:

if(!validate_email($_POST['email']))
{
   die("you have not used a correct email address");
}

// or 

$email = $_POST['email'];
if(!validate_email($email)) {
   die("you have not used a correct email address");
}

Hope this helps :)

phorce 131 Posting Whiz in Training Featured Poster

@cam - No, this has to be outside of the class definition.
You're delcaring a static reference, the class has to know where it is initialised.

phorce 131 Posting Whiz in Training Featured Poster

Like @prit said, are you sure you have the right port? Are you sure this port is open? I Persume that you're using local machines (i.e. not a server) for this?

phorce 131 Posting Whiz in Training Featured Poster

This question cannot be answered; since, it depends purely on the programmer and their preferences. (Bit like the Mac vs Windows arguement) each have their own strenths and own weaknesses and based on those, you should make your own decision.

phorce 131 Posting Whiz in Training Featured Poster

It is all well and good to concentrate on "coding" type security preventions, but, what are you doing in terms of server-side? I.e. "Hackers" or people who want to generally cause a havoc to your website might not generally go down the route of XSS or trying to find vunerabilities inside your code.

What if, for example they managed to get onto your server? Since, all your files, and mysql databases are stored on your server - They don't even need to look for vunerabilities within your code.

What if, they managed to DDoS/DoS your site? Corrupt your database files etc.. I wouldn't just look at coding techniques in terms of security - Make sure your server is 100% secure.

:)

phorce 131 Posting Whiz in Training Featured Poster

Not at all. Although, that's why the forum is there.. So just post your question there :)

phorce 131 Posting Whiz in Training Featured Poster

C++ is a massive language, that requires years and years of experties in order to do the smallest of tasks. Let me give you a simple example: Let's say I want to develop an algorithm for an FFT (Fast Fourier Transform) pretty common in signal processing.

In Python I would:

from cmath import exp, pi

def fft(x):
    N = len(x)
    if N <= 1: return x
    even = fft(x[0::2])
    odd =  fft(x[1::2])
    return [even[k] + exp(-2j*pi*k/N)*odd[k] for k in xrange(N/2)] + \
           [even[k] - exp(-2j*pi*k/N)*odd[k] for k in xrange(N/2)]

print fft([1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0])

Whereas in C++

#include <complex>
#include <iostream>
#include <valarray>

const double PI = 3.141592653589793238460;

typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;

// Cooley–Tukey FFT (in-place)
void fft(CArray& x)
{
    const size_t N = x.size();
    if (N <= 1) return;

    // divide
    CArray even = x[std::slice(0, N/2, 2)];
    CArray  odd = x[std::slice(1, N/2, 2)];

    // conquer
    fft(even);
    fft(odd);

    // combine
    for (size_t k = 0; k < N/2; ++k)
    {
        Complex t = std::polar(1.0, -2 * PI * k / N) * odd[k];
        x[k    ] = even[k] + t;
        x[k+N/2] = even[k] - t;
    }
}

// inverse fft (in-place)
void ifft(CArray& x)
{
    // conjugate the complex numbers
    x = x.apply(std::conj);

    // forward fft
    fft( x );

    // conjugate the complex numbers again
    x = x.apply(std::conj);

    // scale the numbers
    x /= x.size();
}

int main()
{
    const Complex test[] = { 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0 …
phorce 131 Posting Whiz in Training Featured Poster

Did you not ask this in C++? :S Choose which language you're going to work in.. Better still, build it in one language and make an interface in different languages? Don't re-invent code in multiple languages, unless you absolutely have to.

phorce 131 Posting Whiz in Training Featured Poster

This is not going to make much of an impact but: I personally don't think books of programming are a good option. (Ok, in terms of software methodologies: Agile, sofware concents such as lifecycles) but in terms of coding I do not.. Here's why:

1) You learn THEIR coding styles, and THEIR coding techniques on how to do something. Sure, as a reference it's great but you tend to pick up their habbits and their habbits might not be the best way to go.

2) Books become out-dated, very, very quickly. You might be reading references to something that has been published 5 years ago and therefore the particular method becomes depciated. This means that you'll get fustrated with code. For example: Let's say I wanted to learn PHP, and, I picked up a copy of Larry Ullmans book.. It has an example that clearly states that mysql_* is the best option to use.. I then learn that mysql_* functions are now depeciated, so, i've written his solution and yet again, I'm on Google, I'm on forums only to learn that PDO/MYSQLI_* are the new standards.. Do I purchase more books?

If you take forum communities, websites and online referencing to many many things out there in terms of physical programming then you get to pick up multiple techniques. Usually you will see a problem and different members also contribute with their own standards. Languages such as C++ have an array of methods in which you can solve particular problems …

phorce 131 Posting Whiz in Training Featured Poster

@Anima Gives you some great recommendations, with regards to Python. Python is easy to learn and is becoming a lot more popular in commercial sense. Some programmers that have been developing for many, many years are taking up Python now because it offers such a high commercial gain; even if the job isn't in Python.

phorce 131 Posting Whiz in Training Featured Poster

Also, how do you plan on setting this data out? I.e.

If you took the char array of vals as: char s[] = "C 129.2 hi 69.8 This 38.9 World"; and tokenising would become:

Token: 0 -> C
Token: 1 -> 129.2
Token: 2 -> hi
Token: 3 -> 69.8
Token: 4 -> This
Token: 5 -> 38.9
Token: 6 -> World

How would you potentially store this as a std::map since:

std::map<char, std::string> vals {

     myMap['C'] = "129.2 hi 69.8 This 38.9 World"; 

};`

Is a possibility, however, if 129.2 hi 69.8 This 38.9 World are paramaters (for some function) would you not need to tokenise these seperately as well? Are you sure using a std::map is the best way to go for this?

phorce 131 Posting Whiz in Training Featured Poster

So, just to be clear: You want to tokenise the value, and then place them inside a std::map, which contains:

["c"] = 129.2
["b"] = 131.1

and then acess from this?

Also, can you give a small snippet of what the text file looks like, i.e. a few lines =)

phorce 131 Posting Whiz in Training Featured Poster

What's the question?

phorce 131 Posting Whiz in Training Featured Poster

OAuth can seem like a daunting task to implement, although, can be worth-while.

First of all: Choose the return type

What I mean by this is: How do you want the data to be processed? Should you use XML or JSON? It's entirely up to you, you might specifiy what the user wants and therefore chooses.

Second of all: Security

If people are accessing your data, you want to know who they are, right? You don' want someone randomly accessing all of your records. So, what you need to decide is which data is going to become available and to who.

You can specify the who by making sure that the users of the site have to request an API key from you; this key, once accepted is stored inside a database and you can deny access from this API should they start doing things that break the rules. Only members, whom have a valid API key should be allowed to request data.

If they wanted to sign in from the app, then, sure, that's possible. You could ensure that they have an API key. I suggest you read some more on API's to help you gain more knowlege before you start building your own.

EDIT:

Your question seems to broad, which, is probably going to land yourself getting answers that might not be what you're looking for. Which tells me that you do not understand the concepts of API's therefore, I have suggested that you research them, find out …

phorce 131 Posting Whiz in Training Featured Poster

Could you not just read the values inside a char array and then tokenise it?

It's very unclear, I don't understand really what you want to do. Is it possible to show the type of data in the file you're trying to process?

phorce 131 Posting Whiz in Training Featured Poster

Loading DaniWeb today was very slow.. Been like it most of the day and I have just been able to get on. mhm. Anyone else?

phorce 131 Posting Whiz in Training Featured Poster

@down-voter - Please could you explain why this post has been downvoted?

phorce 131 Posting Whiz in Training Featured Poster

I disagree that Tex/LaTeX is a 'Legacy' language.. I agree that there should be a place for it, but, that's a different topic.

Anyway, I'd say stick your question in Computer Science

phorce 131 Posting Whiz in Training Featured Poster

Alternatively, have one standard.. PDF (which is compatible through many operating systems) thus providing that all documents can be open in the web browser.

phorce 131 Posting Whiz in Training Featured Poster

Because I'm learning Python at the moment, I'm going to give you a start.. Something like this:

import string
import random 

def FlipCoin(): 

    coin = ['heads', 'tails'];

    return random.choice(coin);

def main():

    heads = 0;
    tails = 0;

    for x in range(0, 100):
        print FlipCoin();

main();

I'm sure that you can finish this off. :)

phorce 131 Posting Whiz in Training Featured Poster

What do you mean 'Frequency of Age'? Frequency means something else.. Do you know the how frequent a particular age is given?

phorce 131 Posting Whiz in Training Featured Poster

Here is an example:

A 2D array is initialised and represented as the following:

(type) -> name - > [][]

So as follows:

int 2darray[100][100]

This initialises a value of 100 rows and 100 cols note that in memory it is still a 1D block of data, the compiler, therefore, does not allocate data for rows and cols.

The following can be seen as a 2D array:

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

    int vals[100][100]; // 100 rows, 100 cols

    for(unsigned i=0; (i < 100); i++)
    {
        for(unsigned j=0; (j < 100); j++)
        {
            vals[i][j] = 0;

        }
    }
}

This can also be repesented as a 1D block (example, given above) where the memory is allocated for a 1D block, however, how we access it and therefore read from it changes.

Does this make more sense? Or, is there a specific question on 2D arrays?

phorce 131 Posting Whiz in Training Featured Poster

What is contained in company[i][j] there isn't a lot to go on from this.

phorce 131 Posting Whiz in Training Featured Poster

But.. is buildingName a field name inside your database/table? And contains the data that you are sending through the form? If it isn't, the query will never be true.

<?php

            $buildingName = $_POST['buildingName'];
            $roomId = $_POST['roomId'];

            $sql = mysql_query("SELECT * FROM forestcourt WHERE buildingName=$buildingName AND id=$roomId") or die("There was an error" + mysql_error());           

            $num_rows = mysql_num_rows($sql);

            if(num_rows >= 1)
            {
                 $id2 = 'id';
                 $buildingName = 'buildingName';
                 $subBuildings = 'subBuildings';
                 $imagePath = 'imagePath';
                 $description = 'description';

                 while($row2 = mysql_fetch_assoc($sql))
                 {
                     echo 'Name: ' . $rows2[$buildingName] . '<br/>' . 'Room Number: ' . $rows2[$id2] . '<br/>' . 'Sub Buildings: ' . $rows2[$subBuildings] . '<br/>' . 'Description: ' . $rows2[$description] . '<br/>' . 'Location: ' . '<img src="../' . $rows2[$imagePath] . '"/>' . '<br/><br/>';         
                 }



            }else{
              echo "Cannot get data from table";


        ?>

Sorry, I forgot the else statement.

phorce 131 Posting Whiz in Training Featured Poster

I cleaned results up:

<?php

            $buildingName = $_POST['buildingName'];
            $roomId = $_POST['roomId'];

            $sql = mysql_query("SELECT * FROM forestcourt WHERE buildingName=$buildingName AND id=$roomId") or die("There was an error" + mysql_error());           

            $num_rows = mysql_num_rows($sql);

            if(num_rows >= 1)
            {
                 $id2 = 'id';
                 $buildingName = 'buildingName';
                 $subBuildings = 'subBuildings';
                 $imagePath = 'imagePath';
                 $description = 'description';

                 while($row2 = mysql_fetch_assoc($sql))
                 {
                     echo 'Name: ' . $rows2[$buildingName] . '<br/>' . 'Room Number: ' . $rows2[$id2] . '<br/>' . 'Sub Buildings: ' . $rows2[$subBuildings] . '<br/>' . 'Description: ' . $rows2[$description] . '<br/>' . 'Location: ' . '<img src="../' . $rows2[$imagePath] . '"/>' . '<br/><br/>';         
                 }



            }

        ?>

Try inserting both text fields and this should give an error, if there is one.. If there isn't one, then I would check whether or not buildingName is actually a field name. Hope this helps

phorce 131 Posting Whiz in Training Featured Poster

Hey Lewis, I don't unerstand what you mean exactly.. It's only working with one of your input fields? Do you mean that only one result from the database is showing?

phorce 131 Posting Whiz in Training Featured Poster

Files that are stored on the server, or, local machine? What do you mean "had no success" - What happened? Errors?