473,781 Members | 2,718 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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","dia monds","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()%1 3;

while(wdeck[row][column]!=0)
{
row=rand()%4;
column=rand()%1 3;
}
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;co lumn<=12;column ++)

if(wdeck[row][column]==card)
printf("%5s of
%8s%c",wface[column],wsuit[row],card%2==0?'\n' :'\t');
}
Nov 14 '05 #1
3 1697


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.

Nov 14 '05 #2
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","dia monds","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()%1 3;

while(wdeck[row][column]!=0)
{
row=rand()%4;
column=rand()%1 3;
}
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;co lumn<=12;column ++)

if(wdeck[row][column]==card)
printf("%5s of
%8s%c",wface[column],wsuit[row],card%2==0?'\n' :'\t');
}

Nov 14 '05 #3
thanks,it work well.
ÔÚ Tue, 10 Aug 2004 01:20:33 -0400£¬Martin Ambuhl <ma*****@earthl ink.net>
дµÀ:
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","dia monds","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()%1 3;
while(wdeck[row][column]!=0)
{
row=rand()%4;
column=rand()%1 3;
}
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;co lumn<=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/
Nov 14 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
4159
by: toby casey | last post by:
Dear all, I am brand new to php, but learning quickly. I need to be able to go to website, obtain the form elements, cycle through the form elements, fetch the links for each page that results from the submission of the form elements, and then fetch all the content of the pages refered in the links (its approx 115,000 links). If i understand it right, Snoopy is the way to go with this. But the problem is, is that we cannot get snoopy...
4
2756
by: Harald Mossige | last post by:
Dev-Cpp "dont se" MinGW. (Win2K) I have downloaded and run: devlup4991nomingw_setup.exe and MinGW-3.1.0-1.exe in those dirrectory:
7
1762
by: Tina | last post by:
I have an asp project that has 144 aspx/ascx pages, most with large code-behind files. Recently my dev box has been straining and taking long times to reneder the pages in the dev environment. After addding another Crystal report, vs.net will no longer build the project - it just goes away - no message no nothing. My other dev box will build it but won't run it in debug. I ran a vs.net repair but it still does the same thing. vs.net...
3
4412
by: Richard Lewis Haggard | last post by:
We are having a lot of trouble with problems relating to failures relating to 'The located assembly's manifest definition with name 'xxx' does not match the assembly reference" but none of us here really understand how this could be an issue. The assemblies that the system is complaining about are ones that we build here and we're not changing version numbers on anything. The errors come and go with no apparent rhyme or reason. We do not...
13
2103
by: Protoman | last post by:
Here's a non intrusive reference counting smart pointer class I'm working on; I keep getting a "22 C:\Dev-Cpp\SmrtPtr.hpp ISO C++ forbids declaration of `SmrtPtrDB' with no type" error. Code: SmrtPtr.hpp #pragma once
0
1301
by: [Cool staff!||Hi! I think this need for || Help me | last post by:
http://con-cern.org/files/2007/5/xenical-21024312.html cheap xenical http://con-cern.org/files/2007/5/auto-21024411.html auto loan refinance http://tag-dev.jot.com/WikiHome/pharmacy/xenical_html___117970823717048_96302128227356?jot.viewName=xenical.html&theme=none buy xenical http://tag-dev.jot.com/WikiHome/pharmacy/auto_html___117970831070975_10304845439619?jot.viewName=auto.html&theme=none auto loan refinance ,...
8
1773
by: Lloyd Sheen | last post by:
I have a list of JPG's which are found in a SQL Server database. When the page selects a certain piece of data it will refer to the file system (resident on IIS server with a virtual directory) and files contained within a certain folder. I have been trying for quite a while to set the ImageURL of an image control to the correct information. I have googled till my mind hurts but can find nothing to help. I have even tried to copy the...
25
2649
by: tooru honda | last post by:
Hi, I have read the source code of the built-in random module, random.py. After also reading Wiki article on Knuth Shuffle algorithm, I wonder if the shuffle method implemented in random.py produces results with modulo bias. The reasoning is as follows: Because the method random() only produces finitely many possible results, we get modulo bias when the number of possible results is not divisible by the size of the shuffled list.
1
7113
by: =?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?= | last post by:
I get the above error in some of the ASP.NET web applications on a server, and I need some help figuring out how to deal with it. This is a rather long post, and I hope I have enough details that someone who bothers to read all of it have some pointers. Note, I have posted the stack trace and the code exhibiting the problem further down so if you want to start by reading that, search for +++ Also note that I am unable to reproduce...
16
2327
by: Harry Simpson | last post by:
I've been away from ASPNET - I open up a new Web app in VS2008 and go into properties and select to use IIS instead of the personal web server. Then I run in debug mode and it says I have to set the Debug= True in the Web.config which I do. Then try to run it again and it says I must enable integrated security which I do. I then try to run it again and get the HTTP 403 error - " This error (HTTP 403 Forbidden) means that Internet...
0
10308
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10143
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9939
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8964
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7486
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6729
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5507
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4040
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3633
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.