Home > Back-end >  Everyone a great god. Can you tell me what is this piece of C code translated into Delphi?
Everyone a great god. Can you tell me what is this piece of C code translated into Delphi?

Time:09-20

Everyone a great god, what is this period of c + + code translated into Delphi?
Void CommentAsc (char * soustr, short len, unsigned char * desstr)
{
Int I, ch.
Char TMPSTR [53248]={0};

Sprintf (TMPSTR, "s" % *. *, len, len, soustr);
for( i=0; i{
Sscanf (TMPSTR + I * 2, "% 02 x", & amp; Ch);
Desstr [I]=ch & amp; 0 XFF.
}
Desstr [I]='\ 0';
}

CodePudding user response:

Procedure TForm1.Com mentAsc (soustr: string; Len: Integer; Var desstr: string);
Var
I: Integer;
Ch, TMPSTR FormatStr: string;
The result: an array of Char;
AChar: Char;
The begin
//in m.n "% s", m said occupy the width (the length of the string is insufficient to fill the blank space, beyond the width is according to the actual printing)
//that n from the corresponding string in taking up the number of characters,
SetLength (result, div (len + 1) 2 + 1);
FormatStr:='%' + inttostr (len) + ' '+ inttostr (len) +' s'.
TMPSTR:=Format (FormatStr, [soustr]);
I:=0;
While iThe begin
Ch:=format (' %. 2 x '[StrToIntDef (TMPSTR, 0) + I * 2]).
AChar:=char (StrToIntDef (' $' + ch, 0));
Result: [I]=aChar;
I:=I + 1;
end;
Desstr: string=(result);
end;

CodePudding user response:

1. No tform1 something, this is a global function
2. StrToIntDef (TMPSTR, 0) + I * 2 this apparent to C code wrong
3. If the same translation, should use PAnsiChar char *, if use the string, short len this parameter can not
4. The code is bloated
  • Related