phorce 131 Posting Whiz in Training Featured Poster

Would you forgive me if I told you I was an idiot? Sorry aha!

Once I've swopped the value, do I need to remove it from the array and find the next highest value? Like.. It needs to do this 26 types (to go through each number) so for example:


Array 1:

10
20
40
70 -> found and swopped

Array 2:

5
3
10
18 -> found and swopped
2

and then it would do:

Array 1:

10
20
40 -> found and swopped

Array 2:

5
3
10 -> founded and swopped
2

Until all the elements are found?

Thanks so much!

phorce 131 Posting Whiz in Training Featured Poster

Heyy

int analysis[27] = {8, 2, 3, 4, 13, 2, 2, 6, 7, 0, 1, 4, 2, 7, 8, 2, 0, 6, 6, 9, 3, 1, 2,0,2,0};
int size = sizeof(analysis)/sizeof(analysis[0]);
int main()
{
      int max2 = index_of_max(analysis, size);
      cout << max2 << endl;
     return EXIT_SUCCESS;
}

int index_of_max(int a[], int size)
{
    int max = 0;
    
    for (int i = 1; i < size; i++) {
        if (a[i] > a[max])
            max = i;
    }
    
    return max;
}

Thanks

phorce 131 Posting Whiz in Training Featured Poster

Heyy thanks for the reply..

It gives me 13? Which isn't the highest value

phorce 131 Posting Whiz in Training Featured Poster

Hello,

I have two arrays that contain different numbers that I need to compare with another array.. e.g.

Array 1:

10
20
40
70

Array 2:

5
3
10
18
2

Basically, I want to write a program that calculates the highest value each array and then swops the values..

So like: 70 is the highest value in array 1, and 18 is the highest value of array 2 so these have to be swopped.. Here's the code:

int max = 0; int max2 = 0;
for(int i=0; (i < size); i++)
    {
        max = counter[0];

        if(counter[i] >= max)
        {
            max = counter[i];
        }
        
        for(int j=0; (j < size); j++)
        {
            max2 = counter[0];
            if(counter[j] >= max)
            {
                max2 = counter[j];
            }
        }
    }

Any suggestions?

phorce 131 Posting Whiz in Training Featured Poster

Hello,

Thanks for your reply.. Let me try and understand it.. It'll search through the list until an exact match is made?

phorce 131 Posting Whiz in Training Featured Poster

Hey,

I tried that and 'rounded them up / down depending on it.. However it doesn't solve the fact that if there are two values, how do I get the correct one? If there are two '8's would a 2D array be better to store them?

phorce 131 Posting Whiz in Training Featured Poster

Yes!! Basically :P but in decimal places!!

phorce 131 Posting Whiz in Training Featured Poster

Actually comparing the values..
(values from file): (Alphabet Analysis):
A = 8.1 B = 1.3
B = 1.2 A = 1.2
C = 4.6 C = 8.2
D = 1.1 D = 8.4


If I compared A (values from file) with (Alphabet analysis) it won't allow it because there isn't 8.1 but only 8.2 and 8.4 so I need a way of:

- Comparing the first digit (8) -- It matches
- Compare the second digit(1, 2) -- 1 is closer to 2 and not 4 so therefore 8.2 is matched
- A = C

Make sense? Aha sorry for the confusion!

phorce 131 Posting Whiz in Training Featured Poster

No ha, the char array will be the size of the text file that get's read in.. My problem is that i'm working in percentages and decimal places... Here's another example:

(values from file): (Alphabet Analysis):

A = 8.2 B = 1.3
B = 1.2 A = 1.2
C = 4.6 C = 8.2
D = 1.1 D = 8.4

Now A should be replaced with C, however there are two values with 8...

phorce 131 Posting Whiz in Training Featured Poster

That example uses whole numbers and works perfect.. Just, the main one uses percentages with one decimal place!

phorce 131 Posting Whiz in Training Featured Poster

Are you using percentages, raw values or positions? - Percentages

Why are the values staggered? - How do you mean?

Are you swapping, replacing or matching? - Storing the value into another array.

Take a look at some example code (on a small scale):

using System;

namespace asfasfasf
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			
			char[] alphabet = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
			double[] anaylsis = {5, 10, 2, 1, 0};
			double[] alpha = {10, 5, 1, 2, 0};
			char [] decryt = new char[5];
			for(int i=0; (i < 5); i++)
			{
				Console.WriteLine ("Letter: " + alphabet[i] + " = {0}", anaylsis[i]);
				Console.WriteLine ("\t\t\t Letter: " + alphabet[i] + " = {0}", alpha[i]);
			    for(int o=0; (o < alpha.Length); o++)
				{
					if(anaylsis[i] == alpha[o])
					{
						decryt[i] = alphabet[o];
					}
				}
			}
			
			for(int i=0; (i < 5); i++)
			{
				Console.WriteLine("\n\n\n" + decryt[i]);
			}
		}
	}
}

Does that clear it up anymore? Thanks for the reply =)

phorce 131 Posting Whiz in Training Featured Poster

Hello,

Thank you for your reply..

So basically, on the left is the text analysis of a text file (containing text) and the values on the right is the text analysis of the english alphabet. What I need to do is change the value of the left depending on the percentage of the right.. so for example:

A = 10 A = 5
B = 5 B = 10

A = B
B = A

However, because this uses multiple values - It's a lot harder

Does that make it any clear?

phorce 131 Posting Whiz in Training Featured Poster

Hello, I'm doing a project where I need to see which number matches to a list of letters in the alphabet.

Currently I have the output as:

A= 5
				 A= 8
B= 9
				 B= 2
C= 0
				 C= 3
D= 6
				 D= 4
E= 1
				 E= 13
F= 0
				 F= 2
G= 9
				 G= 2
H= 3
				 H= 6
I= 4
				 I= 7
J= 4
				 J= 0
K= 3
				 K= 1
L= 3
				 L= 4
M= 1
				 M= 2
N= 10
				 N= 7
O= 6
				 O= 8
P= 2
				 P= 2
Q= 3
				 Q= 0
R= 8
				 R= 6
S= 0
				 S= 6
T= 3
				 T= 9
U= 2
				 U= 3
V= 3
				 V= 1
W= 5
				 W= 2
X= 0
				 X= 0
Y= 0
			         Y= 2
Z= 8
				 Z= 0

So if B = 9 which can be replaced with with: A -> O -> T because I'm going to do an if statement that checks if the number is like >3 < 3 and then I will store them into a 2D array.

int numbers[27][27]; // This means that "B" can be replaced with 27 characters

And then have a dictionary that checks to see which one matches.. (To see if there's a word)

But I don't know if this would be an efficient method doing the task, and how I would store this in a 2D array..

for(int i=0; (i < alphabet.Length); i++) // This will go through the left numbers
    for(int …
phorce 131 Posting Whiz in Training Featured Poster

Hello,

I'm writing a program that compares two percentages and I need them to be rounded up or down depending on their number.. I have used this:

percentage[i] = Math.Round ((analysis[i] * 100) / char_count);

Bit it throws an error that it's too ambiguous.. Now the "analysis" is a double type and char_count is an integer.

Anyone make any suggestions? Thanks :)

phorce 131 Posting Whiz in Training Featured Poster

Basically, create a list of words which I can then check against a string..

e.g. The man sat down
DICTIONARY
The
man

string contains 2 words from dictionary..

And thanks for replying :)

phorce 131 Posting Whiz in Training Featured Poster

Hello,

I'm trying to read in words from a text file that look like:
The
World
Fell
Over

etc..

But it doesn't seem to be working.. I've written some code however it will only show the first word OR loads of question marks..

string dictionary()
{
    string words[500];
    ifstream openDictionary (dictLoc.c_str());
    
    if(openDictionary.is_open())
    {
        for(int i=0; (i < !openDictionary.eof()); i++)
        {
            openDictionary >> words[i];  
        }

  }else{
        
        cout << "Cannot open the file";
    }    
    return *words;
}

(Function for reading file / storing words)

string lines = dictionary();
    
    for(int i=0; (i < 500); i++)
    {
        cout << lines[i];
    }

(Code for displaying the different words)

Anyone have any ideas? Thanks

phorce 131 Posting Whiz in Training Featured Poster

Hello wonder if you could help me please..

Basically I'm trying to implement a script where it searches through a file and sees the most popular word..

I've got it doing it like this:

Squence: 0 0
Squence: 1 0
Squence: 2 0
Squence: 3 0
Squence: 4 0
Squence: 5 0
Squence: 6 0
Squence: 7 0
Squence: 8 0
Squence: 9 4
Squence: 10 0
Squence: 11 0
Squence: 12 0
Squence: 13 0
Squence: 14 0
Squence: 15 0
Squence: 16 0
Squence: 17 0
Squence: 18 0
Squence: 19 0
Squence: 20 0
Squence: 21 0
Squence: 22 0
Squence: 23 1
Squence: 24 0
Squence: 25 0
Squence: 26 0

And then I'd take the most frequent word (9) now i've tried this:

for (int m=0; (m < 27); m++)
{
    maxNum = max(numbers[m], numbers[m]);
}

Doesn't work.. Also, does anyone know how I would find the actual sequence number, from this? i.e. it finds the maximum number (4) and then displays 9...

Thanks =)

phorce 131 Posting Whiz in Training Featured Poster

Hello, I need to search a char array, for a particular word... E.g.

char * search;
char arr[10] = {'b', 'c', 'a', 't', 'h', 'e', 'p', 'h'};
string words[1] = {"the"};

search = strstr (alphabet, words);

But it doesn't work... Any ideas what the problem could be?

Thanks :)

phorce 131 Posting Whiz in Training Featured Poster

Hey thanks for your reply..

So would would go like this:

int arr[26][10]; // "A" can have 10 different options

Would this work? Or could I use like a Linked-List?

phorce 131 Posting Whiz in Training Featured Poster

I don't know what you're trying to do but shouldn't it be:

bool found = false;

If(x==1||x==2||x==3)
{
   found = true;
}else{
cout<<"Please provide the correct input";
cin >> input;
}

if(found)
{
cout<<"Enter number";
cin>>no;
}

Also, put your code in tags!

phorce 131 Posting Whiz in Training Featured Poster

Hello, I'm working on a project where certain characters can have multiple values.. E.g.

Letter 'A' can be replaced with 'B', 'C', 'D'
Letter 'S' can be replaced with 'X', 'Y'

And then it would output it like this:

A can be replaced with B - Yes/No
A can be replaced with C - Yes/No

Would you use a 2D array?

Thanks :)

phorce 131 Posting Whiz in Training Featured Poster

Hello (Dunno if this is the right forum)

But basically, I've been given some text to decrypt. I've got to do it using frequency analysis. Here's what I've done:

1. Got a frequency analysis of the text: Showing how many times a letter appears.
2. Got a frequency analysis of the alphabet.
3. Compared the values (e.g. if A = 10 then replace it with the letter of the alphabet that has the highest frequency)

But it doesn't seem to be working, just prints out like:

CPLBP GRPVP CUUCCPRG RRPCLGLXURRCV YCV C BRGDCP LB PBRCPRGLX URCGLCRCL RRGPRG, GRLDGR RGV RLUCPVVRLRRVGRC PVPCDGRLR BLCPCCP C BPCX CLPCC RCPC LB RGV RCGDCP. RG VPPLPC GL PP C VLCG LB LLRVGPC, LC VXLPLL CPUCPVPRGRRG C LLRVGPC, LB CBLCL YRRCR LRLX C CRVPCVPC BCRCX CLDLC CLRCPRBP. RB R VCX GRCG LX VLLPYRCG PVGCCBCGCRG RLCGRRCGRLR XRPLCPC  VRLDLGCRPLDV URCGDCPV LB CR LCGLUDV, C CCCGLR, CRC C RDLCR CCCRCCGDCP, R VRCLL RLG PP DRBCRGRBDL GL GRP VURCRG LB GRP GRRRG. C UDLUX, GPRGCCLPC RPCC VDCLLDRGPC C GCLGPVJDP CRC VCCLX PLCX YRGR CDCRLPRGCCX YRRGV, PDG RG YCV GRPGPRPCCL LDGLRRP LB GRP YRLLP YRRCR LCCP RG LLVG VRLCXRRGLX BCRGRGBDL.

Anyone know where I'm going wrong? It's text frequency as well.

Thanks :)

phorce 131 Posting Whiz in Training Featured Poster

Thanks for your help I have managed to solve this now (thankfully) but thank you :)

phorce 131 Posting Whiz in Training Featured Poster

Hey..

Is it possible to make PHP type arrays? Like keys?

For example, I have an array of numbers, and an array of letters..

A = 10
B = 20
C = 30

And then I sort the numbers so that the highest number is at the top etc.. But, it changes the values e.g:

A = 30 // But A = 10

So is there an array that could do this, or anyone suggest any alternative solution to the problem? I use bubble sort that looks like:

void sort_array(int *array, int alphaArray*, int length)//Bubble sort function 
{
    int i,j;
    for(i=0;i<26;i++)
    {
        for(j=0;j<i;j++)
        {
            if(array[i]>array[j])
            {
                int temp=array[i]; //swap 
                array[i]=array[j];
                array[j]=temp;
            }   
        }
    }
    
}

and my array of letters are like:

const char letters[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

Any help would be great, thank you :)

phorce 131 Posting Whiz in Training Featured Poster

Hello,

I have an array and need to sort it so that the highest numbers show first etc..

I have written this:

for(int i=0; (i < 26); i++)
    {
        while(counter[i] < counter[i + 1])
        {
            int temp = counter[i];
    
            counter[i + 1] = temp;
            counter[i] = counter[i + 1];
            
            cout << counter[i];
            cout << counter[i + 1];
        }
    
        cout << " " << alphabetUpper[i] << " " << counter[i] << endl;
        
    }

But it doesn't seem to be working? Any ideas? Thanks

phorce 131 Posting Whiz in Training Featured Poster

Hello,

I'm doing some work on Frequency Analysis and decrypting text..

Basically, this is how I think it works...

You take the alphabet (as a char)

alphabet[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

Then you read in the string you want to analyse

crypt[26] = {'c', 'a', 'b', 'e', 'f', 'f', 'a', 'a'};

Then you calculate how many times each character is used. e.g.
a = 3;
b = 1;
c = 1;
e = 1;

What you do after that is confusing me.. So do you:

1) Swop the values according to how frequent they are displayed in the alphabet? e.g.

if b was most frequent in the alphabet
then
swop b with a;
end

2) Swop pairs of values?

I'm really confused and looking for some guidance, thanks :)

phorce 131 Posting Whiz in Training Featured Poster

Hello I'm trying to display the memory location(s) of an array of pointers. It works, but it prints the memory locations out as:

e.g.

(0x7fff672e19a0)

I know that is the memory location, but in other examples, I've seen it being displayed as

4041

Here is the function:

void display_pointer(int theSize)
{
    int counter = 0;
    for(int i=0; (i < theSize); i++)
    {
        
        char thePointer = myInt[i];
        
        char* ipPtr[theSize];
        
        ipPtr[i]= &thePointer;
        
        cout << *ipPtr[i];
        
        counter++;
    
        if(counter == 11)
        {
            cout << "(" << &ipPtr[i] << ")";
            counter = 0;
            
        }
    }   
}

Thanks =)

phorce 131 Posting Whiz in Training Featured Poster

Hey, thanks for your reply.. Do you mean like:

char alphabet[28] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z', ',' '.' };

??

Also, how would I get around spaces.. that's the main issue i'm having!

phorce 131 Posting Whiz in Training Featured Poster

Hello,

I am working on a script that reads each individual character from a txt file and then outputs it depending on whether it's in the alphabet or not.. The problem is, it won't output spaces or anything apart from the string..

e.g.
The text file reads:

Hello, my name is Phorce and this is a test script.

and the output is:

hellomynameisphorceandthisisatestscript

and here is the .cpp file:

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
    char alphabet[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };
    char alphabetU[26] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' };
    char characters[400];
    char inputted[400];
    int sizeinputted = sizeof(inputted)/sizeof(inputted[0]);
    ifstream file("input.txt");
    
    if(file)
    {
        char words[447];
        for(int i=0; !file.eof(); i++)
		{
            words[i] = file.get();
            for(int o=0; (o < 26); o++)
            {
                if(words[i] == alphabet[o] || words[i] == alphabetU[o])
		   		{
                    inputted[i] = alphabet[o];
                    
                }
                
            }
        }
        
        for(int i=0; (i < sizeinputted); i++)
        {	
            cout << inputted[i];
        }
    }else{
        
        cout << "Cannot open file";
        
    }
    
    
    return EXIT_SUCCESS;
}

Anyone have any ideas? Thanks =)

phorce 131 Posting Whiz in Training Featured Poster

Hello,

I'm developing an application that reads a text file, and then replaces what's in the text file with an array (alphabet) It all works ok until I try and change the position of the inputted character and it returns:

Segmentation fault: 11 It's really confusing!

Here is my code:

#include <iostream>
#include <fstream>
#include <vector>
using namespace std;

bool file_exists(string theFile)
{
	ifstream file(theFile.c_str());
	if(file) 
	{
		
		return true;
	}else{
	  return false;
	}
	
}

int main()
{
	string alphabet[26] = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z" };
	if(file_exists("helloworld.txt"))
	{
		string str;
		string words[1000];
		int* pointer;
		ifstream file("helloworld.txt");
		
		for(int i=0; !file.eof(); i++)
		{
		   words[i] = file.get();
		   for(int o=0; (o < 26); o++)
		   { 
			  if(words[i] == alphabet[o])
			  {
			  	 words[i] = alphabet[o + 9];
			  	 cout << words[i];	
			  	
			}else{
			
			}
		
		  }
	
		}
	}else{
	  cout << "The file does not exist";
	}

	return EXIT_SUCCESS;
}

Any ideas? Thanks =)

phorce 131 Posting Whiz in Training Featured Poster

Hello,

I'm trying to calculate the center of a DIV element. But it doesn't seem to be working, I don't quite get what to do with the calculations.. Here's my code:

<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<style type="text/css">

body {

	background-color: #cccccc;

}

.rectangle {
	
	width: 400px;
	height: 100px;
	border-style:solid;
	border-width:1px;
	
	margin-top: 300px;
	margin-left: 500px;
}


.pointer {
	width: 400px;
	height: 100px;
	
	border-style:solid;
	border-width:1px;
	margin-top: 200px;
	margin-left: 50px;
	
}
</style>

<script>
$(document).ready(function() {
	
	var w = $('.rectangle').width();
	var h = $('.rectangle').height();
	
		var x = w/2; // 200
		var y = h/2; // 50
});

</script>

</head>

<body>
	
	<div class="rectangle"></div>

	<div class="pointer"></div>

</body>

Any ideas? Thanks =)

phorce 131 Posting Whiz in Training Featured Poster

Hello,

I'm using jQuery and trying to create a plugin that draws a rectangle on a canvass. However, it will not even work.. I have tried to create it when I click on a button, this does not work either.. Here is the code:

<html>
<head>

	<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>

	<style type="text/css">
	.cancasing {
		margin-left: 200px;
		margin-top: 100px;
		border-style:solid;
		border-width:1px;
		
		width:900px;
		height:500px;
	}
	
	</style>
	
</head>
	<script type="application/javascript">
	jQuery.fn.drawRect = function(options) {
		
		var defaults = {
			text: 'Default text for div element', 
			x: 10,
			y: 10,
			w: 100,
			h: 200
		};
		
		var options = jQuery.extend(defaults, options);
		
		return this.each(function() {
			$(this) = $(document.createElement('div')).css({border: '1px dotted black'}).addClass("ui-boxer-helper");
		});

	};
	
	$(function()
	{	
	 	var canvas = $("#canvas")[0];
	 	var ctx = canvas.getContext("2d");
	 	
	 	$('#start').click(function()
	 	{
	 		alert ('Hello world');
	 		$.drawRect(
	 		{
	 			text: 'Hello world'
	 		
	 		});
	 	
	 	});
	 	
	});
	
   </script>
  </head>
<body>
	
		<canvas id="canvas" class="cancasing"></canvas>
		<button id="start">Start</button>
		
		
</body>

</html>

Any suggestions please?

phorce 131 Posting Whiz in Training Featured Poster

Hello,

I'm having a problem with a script I'm working on, basically, it outputs a SQL query in JSON, however, it's not doing it properly.. E.g.

Right way:

[{"id":111,"title":"Event1","start":"2011-10-10","url":"http:\/\/yahoo.com\/"},{"id":222,"title":"Event2","start":"2011-10-20","end":"2011-10-22","url":"http:\/\/yahoo.com\/"}]

Wrong way:

[{"id":"1","title":"dfssafsaf","start":"2011-10-22","url":"http:\/\/yahoo.com\/"},{"id":"3","title":"dfssafsaf","start":"1-1-1","url":"http:\/\/yahoo.com\/"}[b],][/b]

As you can see it inserts a ",]" and I only want it to show "]" because it's the end of the results..

Here is the code:

<?php

    $dbh=mysql_connect ("localhost", username", "password") or die('Cannot connect to the database because: ' . mysql_error());
    mysql_select_db ("tbl_name");

    $get_events = "SELECT * FROM calendar";
    $get_results = mysql_query($get_events);
    $i;

    if(mysql_affected_rows() >= 1)
    {   
        echo '[';
        while ($post = mysql_fetch_array($get_results))
        {
            $year = $post['year'];
            $month = $post['month'];
            $day = $post['day'];
            $json = array ('id' => $post['calendar_id'],'title' => "dfssafsaf", 'start' => "$year-$month-$day", 'url' => "http://yahoo.com/");
            $output = json_encode($json) . ',';
            echo $output;   
        }   
        echo ']';

      }else{
      echo 'No';

    }
?>

Any suggestions?

Thanks :)

phorce 131 Posting Whiz in Training Featured Poster

Hello,

Does anyone have any experience with phpwebsocket by google?

I'm having a problem connecting to my server... Here is the two files:

(server.php)

#!/php -q
<?php  /*  >php -q server.php  */

error_reporting(E_ALL);
set_time_limit(0);
ob_implicit_flush();

$master  = WebSocket("[server_IP]",12345);
$sockets = array($master);
$users   = array();
$debug   = false;

while(true){
  $changed = $sockets;
  socket_select($changed,$write=NULL,$except=NULL,NULL);
  foreach($changed as $socket){
    if($socket==$master){
      $client=socket_accept($master);
      if($client<0){ console("socket_accept() failed"); continue; }
      else{ connect($client); }
    }
    else{
      $bytes = @socket_recv($socket,$buffer,2048,0);
      if($bytes==0){ disconnect($socket); }
      else{
        $user = getuserbysocket($socket);
        if(!$user->handshake){ dohandshake($user,$buffer); }
        else{ process($user,$buffer); }
      }
    }
  }
}

//---------------------------------------------------------------
function process($user,$msg){
  $action = unwrap($msg);
  say("< ".$action);
  switch($action){
    case "hello" : send($user->socket,"hello human");                       break;
    case "hi"    : send($user->socket,"zup human");                         break;
    case "name"  : send($user->socket,"my name is Multivac, silly I know"); break;
    case "age"   : send($user->socket,"I am older than time itself");       break;
    case "date"  : send($user->socket,"today is ".date("Y.m.d"));           break;
    case "time"  : send($user->socket,"server time is ".date("H:i:s"));     break;
    case "thanks": send($user->socket,"you're welcome");                    break;
    case "bye"   : send($user->socket,"bye");                               break;
    default      : send($user->socket,$action." not understood");           break;
  }
}

function send($client,$msg){
  say("> ".$msg);
  $msg = wrap($msg);
  socket_write($client,$msg,strlen($msg));
}

function WebSocket($address,$port){
  $master=socket_create(AF_INET, SOCK_STREAM, SOL_TCP)     or die("socket_create() failed");
  socket_set_option($master, SOL_SOCKET, SO_REUSEADDR, 1)  or die("socket_option() failed");
  socket_bind($master, $address, $port)                    or die("socket_bind() failed");
  socket_listen($master,20)                                or die("socket_listen() failed");
  echo "Server Started : ".date('Y-m-d H:i:s')."\n";
  echo "Master socket  : ".$master."\n";
  echo "Listening on   : ".$address." port ".$port."\n\n";
  return $master;
}

function connect($socket){
  global $sockets,$users;
  $user = new User();
  $user->id = uniqid();
  $user->socket = $socket;
  array_push($users,$user);
  array_push($sockets,$socket);
  console($socket." CONNECTED!");
}

function disconnect($socket){
  global $sockets,$users;
  $found=null;
  $n=count($users);
  for($i=0;$i<$n;$i++){
    if($users[$i]->socket==$socket){ $found=$i; break; } …
phorce 131 Posting Whiz in Training Featured Poster

Hello,

I was building a web chat system using jQuery, PHP, and mysql and it's working, the thing is that someone informed me that it will strain the server if I do it this way, and suggested I used "Comet Polling" for it, but I have never heard about it before.. What is the best method to use, for real-time chat rooms?

Thanks :)

phorce 131 Posting Whiz in Training Featured Poster

How do you mean?

If I do this:

<script>
	$(document).ready(function()
	{	
		function LoadMessages() {
			$('#shoutbox').load('chat.php');
		}
		
		//setInterval("LoadMessages();", 1000);
		LoadMessages();
			
	});
	</script>

It will load the message? Not in real-time anyway!

phorce 131 Posting Whiz in Training Featured Poster

Hello,

I am working on a chat application in jQuery and I have used the function setInterval(), however, it doesn't seem to refresh the div element.. Or load it for that matter.. Here is the code:

<!DOCTYPE html>
<html>
<head>
  <style>
  #shoutbox
  {
  	width: 400px;
  	height: 400px;
  	
  	border-style:solid;	
  	border-width:5px;
  }
  
  </style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
	
	<div id="shoutbox">
	
	
	</div>	
	<script>
	$(document).ready(function()
	{	
		function LoadMessages() {
			$('#shoutbox').load('chat.php');
		}
		
		setInterval("LoadMessages()", 10000);
		
			
	});
	</script>
	<form id="chatForm">
		<input type="text" id="chatText" />
		<input type="submit" />
				
	</form>

</body>
</html>

Hope someone cal help, thanks :)

phorce 131 Posting Whiz in Training Featured Poster

Hello,

I am working on an algorithm that checks to see if a value is in an array, however, it doesn't seem to want to work .. It will display that the first number is there but nothing else.. Any ideas? Heres the code:

#include <iostream>
using namespace std;
bool checkNumber(int arr[], int value)
{
	for(int i=0; (i < 10); i++)
	{
		if(value == arr[i])
		{
			return true;	
		}else{
			
			return false;
		}
	}	
}
int main() {
	
	int numbers[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
	
	int value = 2;

	if(checkNumber(numbers, value))
	{
		cout << "Yes";
	
	}else{
		
		cout << "No";
	}
}
phorce 131 Posting Whiz in Training Featured Poster

Hello,

Is it possible to get someones city from their IP address using PHP? I want to display like their local pizza houses near their area using googlemaps..

Please answer :)

phorce 131 Posting Whiz in Training Featured Poster

Sorry, I totally forgot about the class name infront of the methods (It's been a while since I coded C++)

phorce 131 Posting Whiz in Training Featured Poster

Heyy,

Thanks for the reply.. I've sorted the problem out now.. It was because I wasn't linking the files :)

phorce 131 Posting Whiz in Training Featured Poster

Hello,

I have wrote a OO program and I have been able to compile ok when using Dev cpp however, I have moved to mac and now compiling through the terminal.

For classes I use a main.cpp (the main script), Numbers.h (The header file for the class) and Numbers.cpp (all the methods)

Numbers.h:

class Numbers
{
	public:
		Numbers();
		
		Numbers(int theNumber1, int theNumber2);
		void setNumber1 (int theNumber1);
		void setNumber2 (int theNumber2);
		
		int getNumber1();
		int getNumber2();
		
	protected:
	
		int number1;
		int number2;
};

Numbers.cpp

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

Numbers::Numbers(){}

Numbers::Numbers(int theNumber1, int theNumber2)
{
	number1 = theNumber1;
	number2 = theNumber2;
}

void setNumber1 (int theNumber1)
{

}
void setNumber2 (int theNumber2)
{

}
		
int getNumber1()
{

}
int getNumber2()
{

}

Main.cpp:

#include <iostream>

#include "Numbers.h"

int main()
{
	Numbers number;
	
	return 0;
}

And I compile using g++ -o main main.cpp (for example)

And it gives me an error like:

Undefined symbols for architecture x86_64:
  "Numbers::Numbers()", referenced from:
      _main in cczo4aBZ.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

Any ideas? Really annoying me :(

phorce 131 Posting Whiz in Training Featured Poster

Could anyone recommend any commands to connect to port 443 using terminal?

It's a printer website, that enables you to print...

Any ideas?

Thanks you :)

phorce 131 Posting Whiz in Training Featured Poster

Hello,

I want to build a system that allows me to print a document (from a input field) and it prints at my home.
Basically, if I'm out I have an input box that if I upload a file to it, it will print for when I get home. Same if I was sat downstairs I didn't have to mess around with the networking with it.

My printer is always connected to the internet (via my network)

Is this possible, in php?

phorce 131 Posting Whiz in Training Featured Poster

Hey,

Would that mean I can then use:

$this->load->header();

?

phorce 131 Posting Whiz in Training Featured Poster

I'll do an example:

<?php
    
    class Site
    {
          public $var1;
          public $var2;

          public function __construct($theVar1, $theVar2)
          {
              $this->var1 = $theVar1;
              $this->var1 = $theVar2;
          }
    }
?>

That's how I write my classes (Just as example)

If I wanted to do the $this->load->header() would I need:

<?php

     class Load
     {
          
     }

     class Header extends Load
     {

     }
?>

Would this work? :S

phorce 131 Posting Whiz in Training Featured Poster

Hello

When I normally write classes and then use them, I'd use this:

$site = new Site();
$site->load('header');

But I've seen people do this:

$site = new Site();
$site->load->header();

How do they do it? Confused

phorce 131 Posting Whiz in Training Featured Poster

Hello,

I want to create a DDoS prevention script, but I don't know which is the best way to go about it.

What I was thinking is that, when a user attempts to connect to the website, it records their IP and then if there is loads of traffic, it then kicks them off the website?

Also, is there a way in PHP that you can check to see which packets are being sent to the server, and, if there is a large amount of packets coming into the server it then refuses entry?

Thanks.

phorce 131 Posting Whiz in Training Featured Poster

Hello,
(Using Mac as a server)

I have set up a web server (at home) and it's working perfectly fine. However, I'm using ssh to access the files from a different computer and would like to rename and change the location of the "WebServer" server file, basically put it on my desktop and name it something like htdocs.

Any ideas how?

Thanks :)

phorce 131 Posting Whiz in Training Featured Poster

There were no return error.

I have sorted it now though, I saw that I was returning a array anyway so I can just use sizeof(array)
which will return the number anyway.

Thank you for your help guys :)