Can you help me wit this translation attempt pls?

Discussion in 'C Programming' started by almurph@altavista.com, Apr 23, 2009.

  1. Guest

    Hi everyone,


    Hope you can help me with this one and its not too left field. I have
    some pre-99 C code that requires translation into C#. The C code
    involves pointers and the translation does not use any. The
    translatino also tries to simplfy the C code into a kind of easier to
    read code.


    I would apprecte your comments/suggestions/suggestions/blessings to
    make sure I'm on the right track. Oh BTW, it should be noted that
    Weight below is an array of type double.

    Thanking you,
    Al.


    *** BEGIN C LANGUAGE CODE ***


    int A, B;
    double *Wb, *Wa;
    double Sum=0.0;


    for ( Wb = Weight + B, Wa = Weight + A ; Wb <= Wa ; )
    {
    Sum += *Wb++;
    }


    *** END C LANGUAGE CODE ***



    *** BEGIN C# ATTEMPT ***

    double Sum = 0.0;
    double Wt_Value;

    for (double Wt = Weight; Wt <= Weight[A]; Wt++)
    {
    Wt_Value = Wt;
    Sum = Sum + Wt_Value;
    Wt = Wt + 1;
    }

    return Sum;


    *** END C# ATTEMPT ***
    , Apr 23, 2009
    #1
    1. Advertising

  2. Guest

    On Apr 23, 12:59 pm, Richard Heathfield <> wrote:
    > said:
    >
    >
    >
    >
    >
    > > Hi everyone,

    >
    > > Hope you can help me with this one and its not too left field. I
    > > have some pre-99 C code that requires translation into C#. The C
    > > code involves pointers and the translation does not use any. The
    > > translatino also tries to simplfy the C code into a kind of easier
    > > to read code.

    >
    > > I would apprecte your comments/suggestions/suggestions/blessings
    > > to make sure I'm on the right track. Oh BTW, it should be noted
    > > that Weight below is an array of type double.

    >
    > > Thanking you,
    > > Al.

    >
    > > *** BEGIN C LANGUAGE CODE ***

    >
    > > int A, B;
    > > double *Wb, *Wa;
    > > double Sum=0.0;

    >
    > > for ( Wb = Weight + B, Wa = Weight + A ; Wb <= Wa ; )
    > > {
    > >         Sum += *Wb++;
    > > }

    >
    > You might find the following version (which I believe to be
    > equivalent, or as equivalent as possible) to be easier to
    > translate.
    >
    > int A = WhatIsThisSupposedToStartWith();
    > int B = AndWhatAboutThisOne();
    > double Sum = 0.0;
    > while(B <= A)
    > {
    >   Sum = Sum + Weight;
    >   B = B + 1;
    >
    > }
    >
    > --
    > Richard Heathfield <http://www.cpax.org.uk>
    > Email: -http://www. +rjh@
    > Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
    > "Usenet is a strange place" - dmr 29 July 1999- Hide quoted text -
    >
    > - Show quoted text -


    Wow Richard, thanks, very nice & neat man, cool.
    Cheers & thanks again,
    Al.
    , Apr 23, 2009
    #2
    1. Advertising

  3. Fred Guest

    On Apr 23, 4:59 am, Richard Heathfield <> wrote:
    > said:
    >
    >
    >
    >
    >
    > > Hi everyone,

    >
    > > Hope you can help me with this one and its not too left field. I
    > > have some pre-99 C code that requires translation into C#. The C
    > > code involves pointers and the translation does not use any. The
    > > translatino also tries to simplfy the C code into a kind of easier
    > > to read code.

    >
    > > I would apprecte your comments/suggestions/suggestions/blessings
    > > to make sure I'm on the right track. Oh BTW, it should be noted
    > > that Weight below is an array of type double.

    >
    > > Thanking you,
    > > Al.

    >
    > > *** BEGIN C LANGUAGE CODE ***

    >
    > > int A, B;
    > > double *Wb, *Wa;
    > > double Sum=0.0;

    >
    > > for ( Wb = Weight + B, Wa = Weight + A ; Wb <= Wa ; )
    > > {
    > >         Sum += *Wb++;
    > > }

    >
    > You might find the following version (which I believe to be
    > equivalent, or as equivalent as possible) to be easier to
    > translate.
    >
    > int A = WhatIsThisSupposedToStartWith();
    > int B = AndWhatAboutThisOne();
    > double Sum = 0.0;
    > while(B <= A)
    > {
    >   Sum = Sum + Weight;
    >   B = B + 1;
    >
    > }
    >



    sum = 0.0;
    for ( i=B; i < A; i++ ) {
    sum += Weight;
    }

    --
    Fred K.
    Fred, Apr 23, 2009
    #3
  4. CBFalconer Guest

    "" wrote:
    >
    > Hope you can help me with this one and its not too left field. I
    > have some pre-99 C code that requires translation into C#. The C
    > code involves pointers and the translation does not use any. The
    > translatino also tries to simplfy the C code into a kind of
    > easier to read code.


    c.l.c deals only with the C language, as described in the ISO C
    standard. C# is another language, and has no connection to real
    C. Go to another newsgroup, probably something with microsoft in
    the name.

    --
    [mail]: Chuck F (cbfalconer at maineline dot net)
    [page]: <http://cbfalconer.home.att.net>
    Try the download section.
    CBFalconer, Apr 24, 2009
    #4
  5. In article <gsr66i$pgn$>,
    Richard <> wrote:
    ....
    >To the OP, most people will help if able : do not allow Falconer to put
    >you off. He's a clueless old busy body.


    On his good days...
    Kenny McCormack, Apr 24, 2009
    #5
  6. luserXtrog Guest

    On Apr 23, 8:55 pm, Richard <> wrote:
    > CBFalconer <> writes:
    > > "" wrote:

    >
    > >> Hope you can help me with this one and its not too left field. I
    > >> have some pre-99 C code that requires translation into C#. The C
    > >> code involves pointers and the translation does not use any. The
    > >> translatino also tries to simplfy the C code into a kind of
    > >> easier to read code.

    >
    > > c.l.c deals only with the C language, as described in the ISO C
    > > standard.

    >
    > Wrong. c.l.c deals with the C language is used in the real world. ISO C
    > is one variation.
    >
    > To the OP, most people will help if able : do not allow Falconer to put
    > you off. He's a clueless old busy body.
    >


    While his tone may have been unfriendly, the advice is sound.
    C# is a different language and there's likely a more useful
    place for these questions.

    --
    lxt
    luserXtrog, Apr 24, 2009
    #6
  7. luserXtrog Guest

    On Apr 23, 10:32 pm, CBFalconer <> wrote:
    > luserXtrog wrote:
    > > Richard <> wrote:
    > >> CBFalconer <> writes:
    > >>> "" wrote:

    >
    > >>>> Hope you can help me with this one and its not too left field.
    > >>>> I have some pre-99 C code that requires translation into C#.
    > >>>> The C code involves pointers and the translation does not use
    > >>>> any. The translatino also tries to simplfy the C code into a
    > >>>> kind of easier to read code.

    >
    > >>> c.l.c deals only with the C language, as described in the ISO C
    > >>> standard.

    >
    > >> Wrong. c.l.c deals with the C language is used in the real world.
    > >> ISO C is one variation.

    >
    > >> To the OP, most people will help if able : do not allow Falconer
    > >> to put you off. He's a clueless old busy body.> >

    >
    > > While his tone may have been unfriendly, the advice is sound.
    > > C# is a different language and there's likely a more useful
    > > place for these questions.

    >
    > The following is the complete actual message I posted, without the
    > cuts imposed by the trolls.  Where do you find it to be
    > 'unfriendly'?
    >
    > >>> c.l.c deals only with the C language, as described in the ISO C
    > >>> standard.  C# is another language, and has no connection to real
    > >>> C.  Go to another newsgroup, probably something with microsoft in
    > >>> the name.


    The imperative mood: "Go to another newsgroup...". It is an order, a
    command. The sentence could be constructed more politely as a
    pertinent assertion: "You will receive better help in another
    newsgroup...".

    Although I do enjoy the suggestion that C# is unreal.
    But, dude, I'm on *your* side here, don't lump me in!
    I ought not to be held responsible for a previous snip in a thread.

    --
    lxt
    luserXtrog, Apr 24, 2009
    #7
  8. James Kuyper Guest

    CBFalconer wrote:
    > "" wrote:
    >> Hope you can help me with this one and its not too left field. I
    >> have some pre-99 C code that requires translation into C#. The C
    >> code involves pointers and the translation does not use any. The
    >> translatino also tries to simplfy the C code into a kind of
    >> easier to read code.

    >
    > c.l.c deals only with the C language, as described in the ISO C
    > standard. C# is another language, and has no connection to real
    > C. Go to another newsgroup, probably something with microsoft in
    > the name.


    His question is about translation between C and C#. What he needs is
    help from someone who knows a lot about both languages. In the abstract,
    he's just as likely to find such a person in comp.lang.c as in a
    newsgroup devoted to C#, and it's just as reasonable (or just as
    unreasonable) to post to either newsgroup.

    In practice, given the historical relationship between C and C#, he's
    more likely to find such double-experts in the C# newsgroup than here.
    He should be well aware of that fact by now, he's been informed of it
    multiple times, and he keeps ignoring that advice and posting his
    questions in a less appropriate place anyway.
    James Kuyper, Apr 24, 2009
    #8
  9. JosephKK Guest

    Try microsoft.public.dotnet.languages.csharp

    It seems to propagate beyond news.microsoft.com

    HTH

    On Thu, 23 Apr 2009 04:40:35 -0700 (PDT), ""
    <> wrote:

    >Hi everyone,
    >
    >
    > Hope you can help me with this one and its not too left field. I have
    >some pre-99 C code that requires translation into C#. The C code
    >involves pointers and the translation does not use any. The
    >translatino also tries to simplfy the C code into a kind of easier to
    >read code.
    >
    >
    > I would apprecte your comments/suggestions/suggestions/blessings to
    >make sure I'm on the right track. Oh BTW, it should be noted that
    >Weight below is an array of type double.
    >
    >Thanking you,
    >Al.
    >
    >
    >*** BEGIN C LANGUAGE CODE ***
    >
    >
    >int A, B;
    >double *Wb, *Wa;
    >double Sum=0.0;
    >
    >
    >for ( Wb = Weight + B, Wa = Weight + A ; Wb <= Wa ; )
    >{
    > Sum += *Wb++;
    >}
    >
    >
    >*** END C LANGUAGE CODE ***
    >
    >
    >
    >*** BEGIN C# ATTEMPT ***
    >
    >double Sum = 0.0;
    >double Wt_Value;
    >
    >for (double Wt = Weight; Wt <= Weight[A]; Wt++)
    >{
    > Wt_Value = Wt;
    > Sum = Sum + Wt_Value;
    > Wt = Wt + 1;
    >}
    >
    >return Sum;
    >
    >
    >*** END C# ATTEMPT ***
    JosephKK, May 6, 2009
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. chessc4c6
    Replies:
    9
    Views:
    480
    Old Wolf
    Mar 8, 2005
  2. J de Boyne Pollard

    need help wit sbrk

    J de Boyne Pollard, Sep 12, 2007, in forum: C++
    Replies:
    0
    Views:
    551
    J de Boyne Pollard
    Sep 12, 2007
  3. Rickli Hansueli

    can I write to a local .txt File wit javascribt?

    Rickli Hansueli, Nov 20, 2003, in forum: Javascript
    Replies:
    5
    Views:
    84
    Mark Szlazak
    Nov 21, 2003
  4. GMI
    Replies:
    3
    Views:
    495
    Tad McClellan
    Jun 19, 2005
  5. Susanne West
    Replies:
    1
    Views:
    103
    smallpond
    Apr 21, 2008
Loading...

Share This Page