Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Basic Powerbasic > Re: C to PB hel...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 6 of 12 Topic 257 of 276
Post > Topic >>

Re: C to PB help.

by "Anonymous" <r1a@[EMAIL PROTECTED] > Oct 26, 2007 at 03:11 PM

One more time. This time I loaded the file in UltraEdit and saved it in 
ANSI/ASCII code DOS format.
--

//---------------------------START OF C 
CODE---------------------------------------

#include <string.h>
#include <memory.h>
#pragma hdrstop

//------------------------------------------------------------------------------------

typedef struct {
 int len;
 int node[];
}heap;

//----------------------------------------------------------------------------------------

int fLeft(int i){return (i << 1) + 1;}

//----------------------------------------------------------------------------------------

 void Swap(int *i, int *j) {

  int k = *j;
  *j    = *i;
  *i    = k;
}

//----------------------------------------------------------------------------------------
void Fix_heap(heap *hp, int i) {

    int m = fLeft(i);
    if (m < hp->len){
      int h = m + 1;
      if (h < hp->len && hp->node[h] > hp->node[m]) m = h;
      if (hp->node[m] > hp->node[i]) {
        Swap(hp->node+i, hp->node+m);
        Fix_heap(hp, m);
      }
    }
  }
//---------------------------------------------------------------------------------------

int main(int argc, char *argv[]) {
    int i;
    int ary[]={9, 2, 10, 12, 7, 5, 8, 1, 3, 5};
    heap *hp = (heap *) malloc(sizeof(int)*10); //9 elem. + len
    memcpy(hp, ary, sizeof(ary));
    Fix_heap(hp, 0);
    for (i=0; i<hp->len; i++) printf(" %i", hp->node[i]);
    getch();
    return 0;
  }
//---------------------------------------------------------------------------

"Judson McClendon" <judmc@[EMAIL PROTECTED]
> skrev i melding 
news:4IjUi.7265$ho4.891@[EMAIL PROTECTED]
> "Anonymous" <r1a@[EMAIL PROTECTED]
> wrote:
>> The C code looks garbled in my news reader...
>
> The C source code is probably from a ?nix system with only a LF
character 
> at the end of the line instead of CRLF. PowerBASIC Console Compiler 
> installs program CRLF in the Samples folder, and it will fix the file.
Or 
> search powerbasic.com for the file LF2CRLF.ZIP which contains such a 
> program.
> -- 
> Judson McClendon      judmc@[EMAIL PROTECTED]
 (remove zero)
> Sun Valley Systems     http://sunvaley.com
> "For God so loved the world that He gave His only begotten Son, that
> whoever believes in Him should not perish but have everlasting life."
>
 




 12 Posts in Topic:
C to PB help.
"Anonymous" <  2007-10-26 08:38:38 
Re: C to PB help.
"Anonymous" <  2007-10-26 08:51:04 
Re: C to PB help.
"Judson McClendon&qu  2007-10-26 05:55:14 
Re: C to PB help.
"Judson McClendon&qu  2007-10-26 07:30:06 
Re: C to PB help.
"Anonymous" <  2007-10-26 14:58:23 
Re: C to PB help.
"Anonymous" <  2007-10-26 15:11:03 
Re: C to PB help.
"Michael Mattias&quo  2007-10-26 13:33:24 
Re: C to PB help.
"Anonymous" <  2007-10-26 15:58:19 
Re: C to PB help.
"Michael Mattias&quo  2007-10-26 14:31:46 
Re: C to PB help.
"Judson McClendon&qu  2007-10-26 15:39:29 
Re: C to PB help.
"Judson McClendon&qu  2007-10-26 09:43:04 
Re: C to PB help.
"Olav Bergesen"  2007-11-12 19:57:05 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 15:35:15 CDT 2008.