G
gdtkd
Unregistered / Unconfirmed
GUEST, unregistred user!
谁可以帮我将以下的C算法换成DELPHI!
谢谢!
//-------------------------------------------------------------
#include "stdafx.h"
#include <stdlib.h>
#include <iostream.h>
#include <memory.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#define ENGLISH 0
#define CHINESE 1
#define FILENAME_MAX_LENGTH 256 //&Icirc;&Auml;&frac14;&thorn;&Atilde;&ucirc;×&icirc;&sup3;¤256×&Ouml;·&ucirc;
#define READ_MAX_LENGTH 1024 //×&ordf;&raquo;&raquo;&Icirc;&Auml;&frac14;&thorn;&micro;&Auml;×&icirc;&acute;ó&sup3;¤&para;&Egrave;
#define WRITE_MAX_LENGTH 1024 //×&ordf;&raquo;&raquo;&Icirc;&Auml;&frac14;&thorn;&micro;&Auml;×&icirc;&acute;ó&sup3;¤&para;&Egrave;
int Str2Hex(char * str);
char * Convert(char * inFileName,char * outFilename )
{
FILE * outFile,* inFile;
int j;
outFile=fopen(outFilename, "wb") ;
char str[] = "0605041582000064F00000480E01";
fputs( str , outFile );
inFile=fopen(inFileName, "rb") ;
int b;
for( b = 0;b < 14;b++)
{
fseek(inFile, 118 + 36*(13-b), SEEK_SET);
if (inFile==NULL)
{
if (inFile==NULL)
cout<<inFileName<<" Input File Open Error !"<<endl ;
}else
{
while (!feof(inFile))
{
for(int i = 0;i < 9
i++)
{
char tmp[5];
fread(tmp, 4, 1, inFile);
int tmpHex = Str2Hex(tmp)
fprintf(outFile, "%02x", tmpHex);
//j += sprintf( buffer , "%d");
}
break;
}
}
}
fclose(outFile) ;
fclose(inFile) ;
FILE *otbstr;
char buffer[281];
int i, ch;
if( (otbstr = fopen( outFilename, "r" )) == NULL )
exit( 0 );
ch = fgetc( otbstr );
for( i=0
(i < 280 ) &&
( feof( otbstr ) == 0 )
i++ )
{
buffer = (char)ch;
ch = fgetc( otbstr );
}
buffer = '/0';
printf( "%s", buffer );
fclose(otbstr)
return buffer;
}
int Str2Hex(char * str)
{
int hex = 0;
for(int i = 3
i >= 0
i--)
{
int lowByte = str%16;
hex += lowByte * pow(2, 8 - ( i + 1 ) * 2);
int highByte = str/16;
hex += highByte * pow( 2, 8 - ( i + 1 ) * 2 + 1);
}
return hex;
}
int main(int argc, char* argv[])
{
char infilename[] = "test3.bmp";
char outfilename[] = "bmp2yyr";
Convert(infilename, outfilename);
return 0;
}
谢谢!
//-------------------------------------------------------------
#include "stdafx.h"
#include <stdlib.h>
#include <iostream.h>
#include <memory.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#define ENGLISH 0
#define CHINESE 1
#define FILENAME_MAX_LENGTH 256 //&Icirc;&Auml;&frac14;&thorn;&Atilde;&ucirc;×&icirc;&sup3;¤256×&Ouml;·&ucirc;
#define READ_MAX_LENGTH 1024 //×&ordf;&raquo;&raquo;&Icirc;&Auml;&frac14;&thorn;&micro;&Auml;×&icirc;&acute;ó&sup3;¤&para;&Egrave;
#define WRITE_MAX_LENGTH 1024 //×&ordf;&raquo;&raquo;&Icirc;&Auml;&frac14;&thorn;&micro;&Auml;×&icirc;&acute;ó&sup3;¤&para;&Egrave;
int Str2Hex(char * str);
char * Convert(char * inFileName,char * outFilename )
{
FILE * outFile,* inFile;
int j;
outFile=fopen(outFilename, "wb") ;
char str[] = "0605041582000064F00000480E01";
fputs( str , outFile );
inFile=fopen(inFileName, "rb") ;
int b;
for( b = 0;b < 14;b++)
{
fseek(inFile, 118 + 36*(13-b), SEEK_SET);
if (inFile==NULL)
{
if (inFile==NULL)
cout<<inFileName<<" Input File Open Error !"<<endl ;
}else
{
while (!feof(inFile))
{
for(int i = 0;i < 9
i++)
{
char tmp[5];
fread(tmp, 4, 1, inFile);
int tmpHex = Str2Hex(tmp)
fprintf(outFile, "%02x", tmpHex);
//j += sprintf( buffer , "%d");
}
break;
}
}
}
fclose(outFile) ;
fclose(inFile) ;
FILE *otbstr;
char buffer[281];
int i, ch;
if( (otbstr = fopen( outFilename, "r" )) == NULL )
exit( 0 );
ch = fgetc( otbstr );
for( i=0
(i < 280 ) &&
( feof( otbstr ) == 0 )
i++ )
{
buffer = (char)ch;
ch = fgetc( otbstr );
}
buffer = '/0';
printf( "%s", buffer );
fclose(otbstr)
return buffer;
}
int Str2Hex(char * str)
{
int hex = 0;
for(int i = 3
i >= 0
i--)
{
int lowByte = str%16;
hex += lowByte * pow(2, 8 - ( i + 1 ) * 2);
int highByte = str/16;
hex += highByte * pow( 2, 8 - ( i + 1 ) * 2 + 1);
}
return hex;
}
int main(int argc, char* argv[])
{
char infilename[] = "test3.bmp";
char outfilename[] = "bmp2yyr";
Convert(infilename, outfilename);
return 0;
}