Re: can anyone help me in correcting this code?

Discussion in 'C Programming' started by Andrew Poelstra, Nov 8, 2006.

  1. On Tue, 2006-11-07 at 23:34 -0800, rake wrote:
    > hi
    > This program will work correctly


    Hardly. This program is a nightmare in many ways.

    <snip unreadable mess of letters>
    > #include <stdio.h>
    > #include <stdlib.h>
    >
    > // Code for function decodeUpper(....)


    Why use // comments? They restrict portability and cause syntax
    errors on Usenet.

    > char decodeUpper(char in_c1)
    > {
    > char c1;
    > if (in_c1 + 19 > 'Z' )
    > {
    > c1 = in_c1 - 'Z' + 'A' - 1 ;}
    > else
    > {
    > c1 = in_c1 + 19;
    > }
    > return(c1);
    > }
    >


    Um... what? I have no idea what practical use that function could
    have.

    > // Code for function decodeLower(....)
    > char decodeLower(unsigned char in_c2)
    > {
    > char c2;
    > if (in_c2 + 9 > 'z')
    > c2 = in_c2 - 'z' + 'a' - 1 ;
    > else
    > {
    > c2 = in_c2 + 9;
    > }
    > return c2;
    > }
    >


    Ditto. What's with all the magic numbers? And why subtract 'z',
    add 'a', and other nonsense?

    > // Code for function percent(....)
    > float percent(int m, int n)
    > {
    > float i;
    > i = (float)m/n;
    > return( 100*i);
    >
    > }


    Why not use a macro? Nothing is evaluated more than once.

    >
    > // Function main begins here.
    >
    > main ()


    int main(void)

    > {
    > // In C, string is just an array of characters terminated by '\0'.
    >
    > char inString[100];
    > char outString[100];
    > int i, j;
    > char c;
    > float percentage;
    > int up_count = 0;
    > int lo_count = 0;
    > int num_count = 0;
    > int length;
    > char p;


    Why so many variables in main? Sounds like a poorly designed
    program to me.

    > // Read input.
    >
    > printf("Enter a message string with no blanks.\n",inString);


    Why did you pass that useless argument to printf()

    > scanf("%s",inString);
    >


    Whoa! What happens when you get more than 99 characters input?

    > // Write a loop for decoding characters of inString.
    > for(i=0,j=0; inString != '\0'; i++)
    > {
    > c = inString;
    > if ( c >= 'A' && c <= 'Z' )


    This is a nonsense test that means nothing.

    > {
    > up_count++;
    > outString[j] =decodeUpper(c);
    > j++;
    > }
    > else if ( c >= 'a' && c <= 'z' )


    Ditto.

    > {
    > lo_count++;
    > outString[j] = decodeLower(c);
    > j++;
    > }
    > else if( c >= '0' && c <= '9' )
    > {


    Not nonsense, but still not a common idiom. Why not use <ctype.h>
    and use isdigit(), isalpha(), isupper(), islower(), et al.?

    > num_count++;
    > outString[j] = ' ';
    > j++;
    > }
    > }
    > printf("\nnUP_COUNT:%d",up_count);


    Why print "nUP_COUNT"? Typos in production code destroy the
    apparent value of your product (especially when combined with
    setting the computer on fire).

    > length = num_count + up_count + lo_count;
    > outString[j]='\0';
    > // Print decoded string.
    > printf("Decoded Message is :%s\n", outString);
    >
    > //Print num_count (count of spaces), length of decoded
    >
    > printf("Length Of Decoded Message is %d\n",length);
    >
    > printf("Count Of Blanks in Decoded Message is %d \n",num_count);
    >
    > //Calculate % by calling function percent and print.
    >
    > percentage = percent(num_count ,length); // [corrected statements]
    > printf("\n%f percent of output is blank\n",percentage);
    > }
    >


    I'm sorry for cross-posting this. It was originally in
    comp.programming and was clearly more topical in comp.lang.c.
    However, my newsreader (Evolution) appears to have no ability
    to set followups. Can anyone help me?

    --
    Andrew Poelstra <http://www.wpsoftware.net>
    For email, use 'apoelstra' at the above site.
    "You're only smart on the outside." -anon.
     
    Andrew Poelstra, Nov 8, 2006
    #1
    1. Advertising

  2. Andrew Poelstra

    CBFalconer Guest

    Andrew Poelstra wrote:
    >

    .... snip ...
    >
    > I'm sorry for cross-posting this. It was originally in
    > comp.programming and was clearly more topical in comp.lang.c.
    > However, my newsreader (Evolution) appears to have no ability
    > to set followups. Can anyone help me?


    Thunderbird, at mozilla.com

    --
    Chuck F (cbfalconer at maineline dot net)
    Available for consulting/temporary embedded and systems.
    <http://cbfalconer.home.att.net>
     
    CBFalconer, Nov 8, 2006
    #2
    1. Advertising

  3. Re: [OT] can anyone help me in correcting this code?

    On Wed, 2006-11-08 at 14:19 -0500, CBFalconer wrote:
    > Andrew Poelstra wrote:
    > >

    > ... snip ...
    > >
    > > I'm sorry for cross-posting this. It was originally in
    > > comp.programming and was clearly more topical in comp.lang.c.
    > > However, my newsreader (Evolution) appears to have no ability
    > > to set followups. Can anyone help me?

    >
    > Thunderbird, at mozilla.com
    >


    I tried Thunderbird. It locked up under stress, far too often.
    I'll consider going back to gnus, though.

    --
    Andrew Poelstra <http://www.wpsoftware.net>
    For email, use 'apoelstra' at the above site.
    "You're only smart on the outside." -anon.
     
    Andrew Poelstra, Nov 9, 2006
    #3
  4. Andrew Poelstra

    Ian Collins Guest

    Re: [OT] can anyone help me in correcting this code?

    Andrew Poelstra wrote:
    > On Wed, 2006-11-08 at 14:19 -0500, CBFalconer wrote:
    >
    >>Andrew Poelstra wrote:
    >>
    >>... snip ...
    >>
    >>>I'm sorry for cross-posting this. It was originally in
    >>>comp.programming and was clearly more topical in comp.lang.c.
    >>>However, my newsreader (Evolution) appears to have no ability
    >>>to set followups. Can anyone help me?

    >>
    >> Thunderbird, at mozilla.com
    >>

    >
    >
    > I tried Thunderbird. It locked up under stress, far too often.
    > I'll consider going back to gnus, though.
    >

    Just curious, how does one stress a mail client?

    --
    Ian Collins.
     
    Ian Collins, Nov 9, 2006
    #4
  5. Re: [OT] can anyone help me in correcting this code?

    On Thu, 2006-11-09 at 14:03 +1300, Ian Collins wrote:
    > Andrew Poelstra wrote:
    > > On Wed, 2006-11-08 at 14:19 -0500, CBFalconer wrote:
    > >
    > >>Andrew Poelstra wrote:
    > >>
    > >>... snip ...
    > >>
    > >>>I'm sorry for cross-posting this. It was originally in
    > >>>comp.programming and was clearly more topical in comp.lang.c.
    > >>>However, my newsreader (Evolution) appears to have no ability
    > >>>to set followups. Can anyone help me?
    > >>
    > >> Thunderbird, at mozilla.com
    > >>

    > >
    > >
    > > I tried Thunderbird. It locked up under stress, far too often.
    > > I'll consider going back to gnus, though.
    > >

    > Just curious, how does one stress a mail client?
    >


    Download thousands of messages at a time from an inconsistent
    server. For the record, Evolution has a similar problem, although
    to a lesser degree. So does slrn. I wish my ISP would just run
    their newsfeed from a working server.

    --
    Andrew Poelstra <http://www.wpsoftware.net>
    For email, use 'apoelstra' at the above site.
    "You're only smart on the outside." -anon.
     
    Andrew Poelstra, Nov 9, 2006
    #5
  6. Andrew Poelstra

    Ian Collins Guest

    Re: [OT] can anyone help me in correcting this code?

    Andrew Poelstra wrote:
    > On Thu, 2006-11-09 at 14:03 +1300, Ian Collins wrote:
    >
    >>Andrew Poelstra wrote:
    >>
    >>>I tried Thunderbird. It locked up under stress, far too often.
    >>>I'll consider going back to gnus, though.
    >>>

    >>
    >>Just curious, how does one stress a mail client?
    >>

    >
    > Download thousands of messages at a time from an inconsistent
    > server. For the record, Evolution has a similar problem, although
    > to a lesser degree. So does slrn. I wish my ISP would just run
    > their newsfeed from a working server.
    >

    Might be easier to change server rather change client.
    news.individual.net is a safe bet.

    --
    Ian Collins.
     
    Ian Collins, Nov 9, 2006
    #6
  7. Andrew Poelstra

    CBFalconer Guest

    Re: [OT] can anyone help me in correcting this code?

    Andrew Poelstra wrote:
    > On Thu, 2006-11-09 at 14:03 +1300, Ian Collins wrote:
    >

    .... snip ...
    >>
    >> Just curious, how does one stress a mail client?

    >
    > Download thousands of messages at a time from an inconsistent
    > server. For the record, Evolution has a similar problem, although
    > to a lesser degree. So does slrn. I wish my ISP would just run
    > their newsfeed from a working server.


    Try teranews.com.

    --
    Chuck F (cbfalconer at maineline dot net)
    Available for consulting/temporary embedded and systems.
    <http://cbfalconer.home.att.net>
     
    CBFalconer, Nov 9, 2006
    #7
  8. Andrew Poelstra

    Richard Bos Guest

    Re: [OT] can anyone help me in correcting this code?

    Ian Collins <> wrote:

    > Andrew Poelstra wrote:
    > > On Wed, 2006-11-08 at 14:19 -0500, CBFalconer wrote:
    > >
    > >>Andrew Poelstra wrote:
    > >>
    > >>>I'm sorry for cross-posting this. It was originally in
    > >>>comp.programming and was clearly more topical in comp.lang.c.
    > >>>However, my newsreader (Evolution) appears to have no ability
    > >>>to set followups. Can anyone help me?
    > >>
    > >> Thunderbird, at mozilla.com

    > >
    > > I tried Thunderbird. It locked up under stress, far too often.


    Try Agent. I've never had that problem.

    > Just curious, how does one stress a mail client?


    Shout at it a lot?

    Richard
     
    Richard Bos, Nov 9, 2006
    #8
  9. Andrew Poelstra

    goose Guest

    [OT]Re: can anyone help me in correcting this code?

    Andrew Poelstra wrote:
    <snipped>
    > I tried Thunderbird. It locked up under stress, far too often.
    > I'll consider going back to gnus, though.
    >


    What? What sort of stress does a newsreader encounter? Are
    you perhaps subscribed to 300 very active binary groups?

    :)

    goose,
     
    goose, Nov 9, 2006
    #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. Wilq
    Replies:
    0
    Views:
    1,396
  2. MCP
    Replies:
    11
    Views:
    1,107
    Andrew Thompson
    Jun 11, 2004
  3. zotkara

    Newbie needs help correcting code

    zotkara, Jan 3, 2006, in forum: C Programming
    Replies:
    25
    Views:
    705
    Randy Howard
    Jan 3, 2006
  4. vv1
    Replies:
    1
    Views:
    440
    T.M. Sommers
    Nov 6, 2006
  5. Dr Dav

    correcting code for larger 2D arrays help

    Dr Dav, May 30, 2007, in forum: C Programming
    Replies:
    2
    Views:
    294
    Keith Thompson
    May 30, 2007
Loading...

Share This Page