help,why does dev-c++ generate the warnings

Discussion in 'C Programming' started by gaulle, Aug 10, 2004.

  1. gaulle

    gaulle Guest

    i'm a newbie in c. now i 'm learning it.i read a code,and compile it in
    dev-c++4.9.9.0.it can
    be compiled and pass.but there are some warnings.while in TC2.0,no any
    warning.it's why?

    #include <stdio.h>
    #include <time.h>
    #include <stdlib.h>

    void shuffle(int[][13]);
    void deal(const int[][13],const char *[],const char *[]);

    main()
    {
    char * suit[4]={"hearts","diamonds","clubs","spades"};
    char * face[13]={"ace","deuce","three","four","five","six","seven"
    ,"eight","nine","ten","jack","queen","king"};
    int deck[4][13]={0};

    srand(time(NULL));

    shuffle(deck);
    deal(deck,face,suit);

    getch();
    return 0;
    }

    void shuffle(int wdeck[][13])
    {
    int card ,row,column;
    for(card=1;card<=52;card++)
    {
    row=rand()%4;
    column=rand()%13;

    while(wdeck[row][column]!=0)
    {
    row=rand()%4;
    column=rand()%13;
    }
    wdeck[row][column]=card;
    }
    }

    void deal(const int wdeck[][13],
    const char *wface[],
    const char *wsuit[])
    {
    int card,row,column;

    for(card=1;card<=52;card++)
    for(row=0;row<=3;row++)
    for(column=0;column<=12;column++)

    if(wdeck[row][column]==card)
    printf("%5s of
    %8s%c",wface[column],wsuit[row],card%2==0?'\n':'\t');
    }
    gaulle, Aug 10, 2004
    #1
    1. Advertising

  2. gaulle

    Ed Morton Guest

    gaulle wrote:

    > i'm a newbie in c. now i 'm learning it.i read a code,and compile it in
    > dev-c++4.9.9.0.it can
    > be compiled and pass.but there are some warnings.while in TC2.0,no any
    > warning.it's why?


    If you want to know why you're getting specific warnings, why, oh why
    would you not post those specific warnings?

    Ed.
    Ed Morton, Aug 10, 2004
    #2
    1. Advertising

  3. gaulle wrote:
    > i'm a newbie in c. now i 'm learning it.i read a code,and compile it in
    > dev-c++4.9.9.0.it can
    > be compiled and pass.but there are some warnings.while in TC2.0,no any
    > warning.it's why?


    The unmodified OP's code is at EOM. Here is an edited version with the
    syntactical problems (and some stylistic ones) fixed & commented on:

    #include <stdio.h>
    #include <time.h>
    #include <stdlib.h>

    void shuffle(int[][13]);

    /* mha: for the 'const' deleted from the line below, see the
    comments between the calls to shuffle and deal. */
    void deal(int[][13], const char *[], const char *[]);

    /* mha: main returns an int. It does so implicitly under the old
    standard, but implicit int is no longer part of the language. I have
    changed 'main()' to the line below. */
    int main(void)
    {
    /* mha: for the 'const' added to the two lines below, see the
    comments between the calls to shuffle and deal. */
    const char *suit[4] = { "hearts", "diamonds", "clubs", "spades" };
    const char *face[13] =
    { "ace", "deuce", "three", "four", "five", "six", "seven",
    "eight", "nine", "ten", "jack", "queen", "king"};

    /* mha: The initialization 'int deck[4][13]={0};' is ok, but fully
    bracketed initializations are better. I have changed it below. */
    int deck[4][13] = { {0} };

    srand(time(NULL));

    shuffle(deck);

    /* mha: deal() takes arguments of types const int[][13], const char
    *[], and const char *[]. But the supplied argments are none of
    them const. Welcome to the world of const poisoning. It is easy
    enough to make suit and face arrays of pointers to const char (see
    declarations above), but deck cannot be made into an array of
    arrays of const int, since shuffle modifies it. This means we need
    to change the type of the 1st parameter that deal expects. */
    deal(deck, face, suit);

    /* mha: the line below referred to a non-standard function 'getch()'.
    I have changed it to a standard function. */
    getchar();
    return 0;
    }

    void shuffle(int wdeck[][13])
    {
    /* mha: I have not touched the four statements calling rand() in this
    function. The FAQ has much better was of using rand() to get a
    value in a range [0,N]. */

    int card, row, column;
    for (card = 1; card <= 52; card++) {
    row = rand() % 4;
    column = rand() % 13;

    while (wdeck[row][column] != 0) {
    row = rand() % 4;
    column = rand() % 13;
    }
    wdeck[row][column] = card;
    }
    }

    /* mha: for the 'const' deleted from the line below, see the
    comments between the calls to shuffle and deal. */
    void deal(int wdeck[][13], const char *wface[], const char *wsuit[])
    {
    int card, row, column;

    for (card = 1; card <= 52; card++)
    for (row = 0; row <= 3; row++)
    for (column = 0; column <= 12; column++)

    if (wdeck[row][column] == card)

    /* mha: The line below had a string literal broken
    internally by a line break. I have fixed it. */
    printf("%5s of%8s%c", wface[column], wsuit[row],
    card % 2 == 0 ? '\n' : '\t');
    }






    [OP's Code]
    >
    > #include <stdio.h>
    > #include <time.h>
    > #include <stdlib.h>
    >
    > void shuffle(int[][13]);
    > void deal(const int[][13],const char *[],const char *[]);
    >
    > main()
    > {
    > char * suit[4]={"hearts","diamonds","clubs","spades"};
    > char * face[13]={"ace","deuce","three","four","five","six","seven"
    > ,"eight","nine","ten","jack","queen","king"};
    > int deck[4][13]={0};
    >
    > srand(time(NULL));
    >
    > shuffle(deck);
    > deal(deck,face,suit);
    >
    > getch();
    > return 0;
    > }
    >
    > void shuffle(int wdeck[][13])
    > {
    > int card ,row,column;
    > for(card=1;card<=52;card++)
    > {
    > row=rand()%4;
    > column=rand()%13;
    >
    > while(wdeck[row][column]!=0)
    > {
    > row=rand()%4;
    > column=rand()%13;
    > }
    > wdeck[row][column]=card;
    > }
    > }
    >
    > void deal(const int wdeck[][13],
    > const char *wface[],
    > const char *wsuit[])
    > {
    > int card,row,column;
    >
    > for(card=1;card<=52;card++)
    > for(row=0;row<=3;row++)
    > for(column=0;column<=12;column++)
    >
    > if(wdeck[row][column]==card)
    > printf("%5s of
    > %8s%c",wface[column],wsuit[row],card%2==0?'\n':'\t');
    > }
    Martin Ambuhl, Aug 10, 2004
    #3
  4. gaulle

    gaulle Guest

    thanks,it work well.
    ÔÚ Tue, 10 Aug 2004 01:20:33 -0400£¬Martin Ambuhl <>
    дµÀ:

    > gaulle wrote:
    >> i'm a newbie in c. now i 'm learning it.i read a code,and compile it
    >> in dev-c++4.9.9.0.it can
    >> be compiled and pass.but there are some warnings.while in TC2.0,no any
    >> warning.it's why?

    >
    > The unmodified OP's code is at EOM. Here is an edited version with the
    > syntactical problems (and some stylistic ones) fixed & commented on:
    >
    > #include <stdio.h>
    > #include <time.h>
    > #include <stdlib.h>
    >
    > void shuffle(int[][13]);
    >
    > /* mha: for the 'const' deleted from the line below, see the
    > comments between the calls to shuffle and deal. */
    > void deal(int[][13], const char *[], const char *[]);
    >
    > /* mha: main returns an int. It does so implicitly under the old
    > standard, but implicit int is no longer part of the language. I have
    > changed 'main()' to the line below. */
    > int main(void)
    > {
    > /* mha: for the 'const' added to the two lines below, see the
    > comments between the calls to shuffle and deal. */
    > const char *suit[4] = { "hearts", "diamonds", "clubs", "spades" };
    > const char *face[13] =
    > { "ace", "deuce", "three", "four", "five", "six", "seven",
    > "eight", "nine", "ten", "jack", "queen", "king"};
    >
    > /* mha: The initialization 'int deck[4][13]={0};' is ok, but fully
    > bracketed initializations are better. I have changed it below. */
    > int deck[4][13] = { {0} };
    >
    > srand(time(NULL));
    >
    > shuffle(deck);
    >
    > /* mha: deal() takes arguments of types const int[][13], const char
    > *[], and const char *[]. But the supplied argments are none of
    > them const. Welcome to the world of const poisoning. It is easy
    > enough to make suit and face arrays of pointers to const char (see
    > declarations above), but deck cannot be made into an array of
    > arrays of const int, since shuffle modifies it. This means we need
    > to change the type of the 1st parameter that deal expects. */
    > deal(deck, face, suit);
    >
    > /* mha: the line below referred to a non-standard function 'getch()'.
    > I have changed it to a standard function. */
    > getchar();
    > return 0;
    > }
    >
    > void shuffle(int wdeck[][13])
    > {
    > /* mha: I have not touched the four statements calling rand() in this
    > function. The FAQ has much better was of using rand() to get a
    > value in a range [0,N]. */
    >
    > int card, row, column;
    > for (card = 1; card <= 52; card++) {
    > row = rand() % 4;
    > column = rand() % 13;
    >
    > while (wdeck[row][column] != 0) {
    > row = rand() % 4;
    > column = rand() % 13;
    > }
    > wdeck[row][column] = card;
    > }
    > }
    >
    > /* mha: for the 'const' deleted from the line below, see the
    > comments between the calls to shuffle and deal. */
    > void deal(int wdeck[][13], const char *wface[], const char *wsuit[])
    > {
    > int card, row, column;
    >
    > for (card = 1; card <= 52; card++)
    > for (row = 0; row <= 3; row++)
    > for (column = 0; column <= 12; column++)
    >
    > if (wdeck[row][column] == card)
    >
    > /* mha: The line below had a string literal broken
    > internally by a line break. I have fixed it. */
    > printf("%5s of%8s%c", wface[column], wsuit[row],
    > card % 2 == 0 ? '\n' : '\t');
    > }
    >
    >
    >
    >
    >
    >
    > [OP's Code]
    >> #include <stdio.h>
    >> #include <time.h>
    >> #include <stdlib.h>
    >> void shuffle(int[][13]);
    >> void deal(const int[][13],const char *[],const char *[]);
    >> main()
    >> {
    >> char * suit[4]={"hearts","diamonds","clubs","spades"};
    >> char * face[13]={"ace","deuce","three","four","five","six","seven"
    >> ,"eight","nine","ten","jack","queen","king"};
    >> int deck[4][13]={0};
    >> srand(time(NULL));
    >> shuffle(deck);
    >> deal(deck,face,suit);
    >> getch();
    >> return 0;
    >> }
    >> void shuffle(int wdeck[][13])
    >> {
    >> int card ,row,column;
    >> for(card=1;card<=52;card++)
    >> {
    >> row=rand()%4;
    >> column=rand()%13;
    >> while(wdeck[row][column]!=0)
    >> {
    >> row=rand()%4;
    >> column=rand()%13;
    >> }
    >> wdeck[row][column]=card;
    >> }
    >> }
    >> void deal(const int wdeck[][13],
    >> const char *wface[],
    >> const char *wsuit[])
    >> {
    >> int card,row,column;
    >> for(card=1;card<=52;card++)
    >> for(row=0;row<=3;row++)
    >> for(column=0;column<=12;column++)
    >> if(wdeck[row][column]==card)
    >> printf("%5s of
    >> %8s%c",wface[column],wsuit[row],card%2==0?'\n':'\t');
    >> }




    --
    ʹÓà Opera ¸ïÃüÐԵĵç×ÓÓʼþ¿Í»§³ÌÐò M2: http://www.opera.com/m2/
    gaulle, Aug 10, 2004
    #4
    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. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    875
    Mark Rae
    Dec 21, 2006
  2. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,804
    Smokey Grindel
    Dec 2, 2006
  3. AMT2K5
    Replies:
    1
    Views:
    924
    AMT2K5
    Aug 4, 2005
  4. Replies:
    3
    Views:
    407
    red floyd
    Apr 7, 2006
  5. Ted Sung
    Replies:
    1
    Views:
    307
    Sherm Pendley
    Aug 30, 2004
Loading...

Share This Page