HI
I am new to php
I would like to ask how I can insert a C source code into a php file
please help
I have a C scheduling algorithm that I'd like to use for my site that I am developing using php/mysql but I don't know how.
Please help
HI
I am new to php
I would like to ask how I can insert a C source code into a php file
please help
I have a C scheduling algorithm that I'd like to use for my site that I am developing using php/mysql but I don't know how.
Please help
Simple answer: Your algo needs to be ported to PHP. There is no way to implement C/C++ code into a php file.
The only way this works would be writing an extension for PHP. This extension is loaded by the php engine and provides your functionality under special function names.
Have a look at http://www.php.net and the PECL or PEAR subsites.
WHy don't you post your c algo here. I'd bet I could port it to php.
http://www.devnewz.com/2002/0909.html
This is a nice "how to" for adding your own libraries using windows. Linux shouldn't be a problem as well, if you know about C/C++ programming on different platforms.
That is the scheduling code,
I 'd really appreciate your help.
Actually I need to do scheduling for a number of teams in the mysql database.
#include <stdio.h>
#include <stdlib.h>
#define FALSE 0
#define TRUE 1
#define MaxTeams 10
#define MaxCombinations (MaxTeams/2)*(MaxTeams-1)
struct game { int one, two ;};
int teams;
long combinations; /* total combinations needed to schedule season */
int a, b, c, i, m,
startC,
matchCount,
roundCount,
index;
long round_set; /* used during searches, if a bit is set then that team has
* already been tenatively scheduled for the round */
long totalChecks;
struct game tourn[1+MaxCombinations]; /* games */
int mList[1+MaxTeams/2]; /* matches */
struct game cList[1+MaxCombinations]; /* combinations list */
int cUsed[1+MaxCombinations]; /* combinations used list */
void ShowSchedule()
{
int index, r, m ;
fprintf( stdout, "\n%d teams", teams );
fprintf( stdout, "\n ");
for (r=1; r <= teams/2; r++) fprintf( stdout, " Game%d", r);
fprintf( stdout, "\n" );
fprintf( stdout, " +-");
for (r=1; r <= (teams/2)*6-2; r++) fprintf( stdout, "-" );
fprintf( stdout, "\n" );
index = 1;
for (r=1; r <= teams-1; r++) {
fprintf( stdout, "Week %2d |", r);
for (m=1; m <= teams/2; m++) {
fprintf( stdout, "%2d&%2d ", tourn[index].one, tourn[index].two );
index++;
}
fprintf( stdout, "\n" );
}
}
void ClearArrays()
{
int i;
for (i=0; i <= MaxCombinations; i++) { tourn[i].one = 0; tourn[i].two = 0; }
for (i=0; i <= MaxTeams/2; i++) mList[i] = 0;
for (i=0; i <= MaxCombinations; i++) { cList[i].one = 0; cList[i].two = 0; }
for (i=0; i <= MaxCombinations; i++) cUsed[i] = 0;
}
main()
{
teams = 2;
while (teams <= MaxTeams) {
combinations = teams/2 * (teams-1);
totalChecks = 0;
ClearArrays();
/* set up list of all combinations */ /* a */
m = 1; /* b 1 2 3 4 5 */
for (a=1; a < teams; a++) /* 1 */
for (b=a+1; b <=teams; b++) { /* 2 . */
cList[m].one = a; /* 3 . . */
cList[m].two = b; /* 4 . . . */
m++; /* 5 . . . . */
}
roundCount = 1;
index = 1;
while (roundCount <= teams-1) {
matchCount = 1;
round_set = 0;
for (i=0; i <= MaxTeams/2; i++) mList[i] = 0;
startC = roundCount;
/* proceed with optimism, we will find matches to fill out the round */
while (matchCount <= teams/2) {
c = combinations + 1;
while (c > combinations) {
c = startC;
/* find an unused pair that would be legitimate */
while ((c <= combinations) &&
((round_set & (1 << cList[c].one)) ||
(round_set & (1 << cList[c].two)) ||
(cUsed[c])
)
)
c++;
if (c > combinations) {
/* did not find an unused legitimate pair, back off */
do {
mList[matchCount] = 0;
matchCount--;
index--;
round_set &= ~(1 << cList[mList[matchCount]].one);
round_set &= ~(1 << cList[mList[matchCount]].two);
cUsed[mList[matchCount]] = FALSE;
tourn[index].one = 0;
tourn[index].two = 0;
} while (cList[mList[matchCount] ].one !=
cList[mList[matchCount]+1].one);
startC = mList[matchCount] + 1;
}
}
/* found a match that fits into the round, keep going until
* all matches in the round have been scheduled
*/
tourn[index] = cList[c];
totalChecks++;
if ((totalChecks % 1000) == 0) fprintf( stdout, "%d\033A\n", totalChecks );
cUsed[c] = TRUE;
mList[matchCount] = c;
startC = 1;
round_set |= (1 << cList[c].one);
round_set |= (1 << cList[c].two);
index++;
matchCount++;
}
/* found enough matches to fill a round, schedule the next round */
roundCount++;
}
fprintf( stdout, " " );
ShowSchedule();
/* try and make a schedule using two more teams */
teams += 2;
}
}
That is the scheduling code,
I 'd really appreciate your help.
Actually I need to do scheduling for a number of teams in the mysql database.
That looks simple enough. The only problem I can see is with that struct.
But I suppose you use use a class instead or take it out altogether.
Passing functions, again that should be simple to do.
And those bitwise operators, thankfully php supports that as well:
http://www.hudzilla.org/php/3_12_3.php
Have a go and see how far you get.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.