Board index » delphi » Translating from Delphi to ANSI C.

Translating from Delphi to ANSI C.

Hi,

I'm new to C programming. Can someone help me to translate the following
Delphi codes into Standard C / ANSI C.

var
    Code1, Code2, Code3, Code4: Integer;
     HugeInt: Int64;
begin
  Code1 := 1234;
  Code2 := 5678;
  Code3 := 9012;
  Code4 := 3456;

  HugeInt := StrToInt64(Format('%4d%.4d%.4d%.4d', [Code1, Code2, Code3,
Code4]));

end;

Thanks for any help.

regards
Bill CTK

 

Re:Translating from Delphi to ANSI C.


Quote
billctk wrote:
> I'm new to C programming. Can someone help me to translate the following
> Delphi codes into Standard C / ANSI C.

> var
>     Code1, Code2, Code3, Code4: Integer;
>      HugeInt: Int64;
> begin
>   Code1 := 1234;
>   Code2 := 5678;
>   Code3 := 9012;
>   Code4 := 3456;

>   HugeInt := StrToInt64(Format('%4d%.4d%.4d%.4d', [Code1, Code2, Code3,
> Code4]));

> end;

I've very little experience with Pascal, and I don't know what Int64
type is, but I'm guessing it's eqivalent in C is 'long'. Also what does
StrToInt64 do ? If I'm guessing it all correctly it will be:

        int code1, code2, code3, code4;
        char buf[16];
        long hugeint;

        code1 = 1234;
        code2 = 5678;
        code3 = 9012
        code4 = 3456;

        sprintf(buf, "%4d%.4d%.4d%.4d", code1, code2, code3, code4);
        hugeint = atol(buf);

If this doesn't give the desired result, tell me what result you expect.

Vimal.

Re:Translating from Delphi to ANSI C.


Quote
> I've very little experience with Pascal, and I don't know what Int64
> type is, but I'm guessing it's eqivalent in C is 'long'. Also what does

If this is a 64 bit Int, then in a Win32 environment, a Borland C 5.0 long will
be 32bits too small.  There are some Windows API functions that will handle
this conversion (depending on the byte order et al).

regards DM

Other Threads