Why fgetc() can not read out the right value in my code ?
Posted: Thu Oct 24, 2002 10:19 am
I am new in PHP. I am trying to convert a CGI/C code to PHP code as below. Both codes are running in the same directory on a Unix server, reading the same file "rgb.dat". The CGI code works fine, the PHP does not work. Problem is the $low and $high get the wrong values by using the fgetc($fp). But the $buf get the right value using the fread() function.
Does the fgetc function in C and PHP work in the same way? I am really confused about that. Please help. Many thanks!
//******** C code *********
seed=12;
fp=fopen("rgb.dat","rb");
fseek(fp,50*seed,SEEK_SET);
fread(buf,26,1,fp);
fseek(fp,50*seed+26,SEEK_SET);
for (i=0;i<12;i++)
{
int low, high;
low =fgetc(fp);
high =fgetc(fp);
N[i]=low+high*100;
}
//****** PHP code ***********
$seed =12;
$fp=fopen("rgb.dat","rb");
fseek($fp,50*$seed,SEEK_SET);
$buf=fread($fp, 26);
fseek($fp,50*$seed+26,SEEK_SET);
for ($i=0;$i<12;$i++)
{
$low =fgetc($fp);
$high =fgetc($fp);
$N[i]=low+high*100;
}
Does the fgetc function in C and PHP work in the same way? I am really confused about that. Please help. Many thanks!
//******** C code *********
seed=12;
fp=fopen("rgb.dat","rb");
fseek(fp,50*seed,SEEK_SET);
fread(buf,26,1,fp);
fseek(fp,50*seed+26,SEEK_SET);
for (i=0;i<12;i++)
{
int low, high;
low =fgetc(fp);
high =fgetc(fp);
N[i]=low+high*100;
}
//****** PHP code ***********
$seed =12;
$fp=fopen("rgb.dat","rb");
fseek($fp,50*$seed,SEEK_SET);
$buf=fread($fp, 26);
fseek($fp,50*$seed+26,SEEK_SET);
for ($i=0;$i<12;$i++)
{
$low =fgetc($fp);
$high =fgetc($fp);
$N[i]=low+high*100;
}