C to Pascal

Dan Mick dan at charyb.COM
Thu Feb 1 15:59:23 AEST 1990


In article <1648 at milton.acs.washington.edu> pingpong at milton.acs.washington.edu (jimmy) writes:
>Does anyone know how to convert the following C code to Pascal code:
>
>int compute_num(char *word)
>{
>   int num=0;
>   while (*word)
>     num = (num << 5) + *word++;
>   return num;
>}
>

Turbo Pascal?  (strings are different than "std" Pascal).  How about:

TYPE string255: string[255];

function ComputeNum(word:string255):integer;

num:integer;
i:integer;
	
begin
	for i := 1 to Length(word) do
		num := num * 32 + Ord(word[i]);
	ComputeNum := num;
end;

You'll have to subsitute the appropriate crud for strings and lengths
and individual chars of a string otherwise, or form them yourself from
a char array with a length or a null terminator, or some such. The
non-standard strings in Pascal is a really silly thing.
	
		
		



More information about the Comp.lang.c mailing list