f



Don't understand why my code isn't working

I've got a simple and repetitive bit of code for a function in a C
implementation of the card game 31s I'm working on. BTW, I am a bit of
a novice at C; for the past couple of years I was using Visual Basic,
but I wanted portability, so I chose C.

I am developing this in XCode 2 (on Mac OS 10.4.7) as a normal C
command line utility; so this is basically just GCC. This code compiles
fine, without any errors or warnings but when I run it in XCode it
says: "31s has exited due to signal 11 (SIGSEGV)." and in Terminal it
says "Segmentation Fault". Here is the code of most of the function,
and what I'm pretty sure is the faulty bit. I can post all the code up
if needed; it's all in one .c file.

void print_stats() {
	int
location_of_player_card_1,location_of_player_card_2,location_of_player_card_3;
	int
location_of_CPU1_card_1,location_of_CPU1_card_2,location_of_CPU1_card_3;
	int
location_of_CPU2_card_1,location_of_CPU2_card_2,location_of_CPU2_card_3;
	int
location_of_middle_card_1,location_of_middle_card_2,location_of_middle_card_3;

	int x,y;
	while (x<52) {
		if (where_are_cards[x] = PLAYER_HAND) {
		switch (y) {
			case 0:
				location_of_player_card_1 = x;
				y++;
				break;
			case 1:
				location_of_player_card_2 = x;
				y++;
				break;
			case 2:
				location_of_player_card_3 = x;
				y++;
				break;
		}
		}
		x++;
	}

	x,y = 0;

	while (x<52) {
		if (where_are_cards[x] = CPU1_HAND) {
		switch (y) {
			case 0:
				location_of_CPU1_card_1 = x;
				y++;
				break;
			case 1:
				location_of_CPU1_card_2 = x;
				y++;
				break;
			case 2:
				location_of_CPU1_card_3 = x;
				y++;
				break;
		}
		}
		x++;
	}

	x,y = 0;

	while (x<52) {
		if (where_are_cards[x] = CPU2_HAND) {
		switch (y) {
			case 0:
				location_of_CPU2_card_1 = x;
				y++;
				break;
			case 1:
				location_of_CPU2_card_2 = x;
				y++;
				break;
			case 2:
				location_of_CPU2_card_3 = x;
				y++;
				break;
		}
		}
		x++;
	}

	x,y = 0;

	while (x<52) {
		if (where_are_cards[x] = MIDDLE) {
		switch (y) {
			case 0:
				location_of_middle_card_1 = x;
				y++;
				break;
			case 1:
				location_of_middle_card_2 = x;
				y++;
				break;
			case 2:
				location_of_middle_card_3 = x;
				y++;
				break;
		}
		}
		x++;
	}

	printf("Table:\n");
	printf("  Your hand: ");
	print_card(pack[location_of_player_card_1]);
	print_card(pack[location_of_player_card_2]);
	print_card(pack[location_of_player_card_3]);

}

0
7/18/2006 2:16:57 PM
comp.lang.c 30657 articles. 5 followers. spinoza1111 (3246) is leader. Post Follow

9 Replies
742 Views

Similar Articles

[PageSpeed] 23

Simon wrote:

>       int x,y;
>       while (x<52) {

The value of `x` is indeterminate. Undefined behaviour. It
might, for example, be -1066 (assuming it's not a trap
value).

>               if (where_are_cards[x] = PLAYER_HAND) {

I'm /sure/ this isn't what you meant to say. You've assigned
`PLAYER_HAND` to `where_are_cards[x]`, and if PLAYER_HAND isn't
zero, you do the then-part (the switch below). I think you
meant to write `==`.

>               switch (y) {
>                       case 0:
>                               location_of_player_card_1 = x;
>                               y++;
>                               break;
>                       case 1:
>                               location_of_player_card_2 = x;
>                               y++;
>                               break;
>                       case 2:
>                               location_of_player_card_3 = x;
>                               y++;
>                               break;
>               }
>               }
>               x++;
>       }

Wouldn't it be better to have location_of_player_card being an
array so you could just write

    location_of_player_card[y] = x;

(if necessary, checking y to be in range)?

>       x,y = 0;

I don't think that does what you think.

What it does is evaluate `x`, throw the value away, then assign 0
to `y`.

I suspect you need to write

    x = y = 0;

>       while (x<52) {
>               if (where_are_cards[x] = CPU1_HAND) {
>               switch (y) {
>                       case 0:
>                               location_of_CPU1_card_1 = x;
>                               y++;
>                               break;
>                       case 1:
>                               location_of_CPU1_card_2 = x;
>                               y++;
>                               break;
>                       case 2:
>                               location_of_CPU1_card_3 = x;
>                               y++;
>                               break;
>               }
>               }
>               x++;
>       }

Almost exactly the same as the code above. Seek to remove duplication.

>       x,y = 0;

As above.

> 
>       while (x<52) {
>               if (where_are_cards[x] = CPU2_HAND) {
>               switch (y) {
>                       case 0:
>                               location_of_CPU2_card_1 = x;
>                               y++;
>                               break;
>                       case 1:
>                               location_of_CPU2_card_2 = x;
>                               y++;
>                               break;
>                       case 2:
>                               location_of_CPU2_card_3 = x;
>                               y++;
>                               break;
>               }
>               }
>               x++;
>       }

As other above.

>       x,y = 0;

Ditto.

>       while (x<52) {
>               if (where_are_cards[x] = MIDDLE) {
>               switch (y) {
>                       case 0:
>                               location_of_middle_card_1 = x;
>                               y++;
>                               break;
>                       case 1:
>                               location_of_middle_card_2 = x;
>                               y++;
>                               break;
>                       case 2:
>                               location_of_middle_card_3 = x;
>                               y++;
>                               break;
>               }
>               }
>               x++;
>       }

Ditto ditto.


-- 
Chris "sekr" Dollin
"Life is full of mysteries. Consider this one of them." Sinclair, /Babylon 5/

0
chris.dollin (1683)
7/18/2006 2:34:31 PM
Thanks, Chris, this is really helpful. I've cleared up stuff you said
in long-hand just to make sure but it's still not quite working - my
program, that is. I've commented out a bit in shuffle_cards which
randomizes but it's still very wierd with all these "signal" errors.
Here's the complete code:

#include <stdio.h>
#include <stdlib.h>   // for srand and rand
#include <time.h>     // for time

typedef struct {
    int suit;   /* The suit of the playing card */
    int value;  /* The value of the playing card */
} CARD;

/* Set up an integer to represent each suit */
enum {CLUBS = 4, DIAMONDS = 3, HEARTS = 2, SPADES= 1};

/* Set up integers to represent non numeric cards */
enum {ACE = 14, JACK = 11, QUEEN = 12, KING = 13};


CARD pack[51];
int where_are_cards[51];
enum {PACK = 0, PLAYER_HAND = 1, CPU1_HAND = 2, CPU2_HAND = 3, MIDDLE =
4};


void print_card(CARD card_to_print) {
if ( card_to_print.value < 11 ) { printf("%d",card_to_print.value); }
if ( card_to_print.value == 11 ) { printf("Jack"); }
if ( card_to_print.value == 12 ) { printf("Queen"); }
if ( card_to_print.value == 13 ) { printf("King"); }
if ( card_to_print.value == 14 ) { printf("Ace"); }

printf(" of ");

if ( card_to_print.suit == 1 ) { printf("Spades"); }
if ( card_to_print.suit == 2 ) { printf("Hearts"); }
if ( card_to_print.suit == 3 ) { printf("Diamonds"); }
if ( card_to_print.suit == 4 ) { printf("Clubs"); }
printf("\n");
}

void shuffle_pack() {
	srand(time(0));  // initialize seed "randomly"
	int i,x,y,z = 0;

	while (x < 4) {
		while (y < 13) {
			pack[x*y].value = y;
			pack[x*y].suit = x;
			y++;
		}
		y = 0;
		x++;
	}
/*
	while (z<52) {
		int r = rand() % 52;  // generate a random position
		CARD temp = pack[i]; pack[i] = pack[r]; pack[r] = temp;
		z++;
	}*/
}

void print_stats() {
	int
location_of_player_card_1,location_of_player_card_2,location_of_player_card_3;
	int
location_of_CPU1_card_1,location_of_CPU1_card_2,location_of_CPU1_card_3;
	int
location_of_CPU2_card_1,location_of_CPU2_card_2,location_of_CPU2_card_3;
	int
location_of_middle_card_1,location_of_middle_card_2,location_of_middle_card_3;

	int x,y = 0;
	while (x<52) {
		if (where_are_cards[x] == PLAYER_HAND) {
		switch (y) {
			case 0:
				location_of_player_card_1 = x;
				y++;
				break;
			case 1:
				location_of_player_card_2 = x;
				y++;
				break;
			case 2:
				location_of_player_card_3 = x;
				y++;
				break;
		}
		}
		x++;
	}

	x = 0;
	x = 0;

	while (x<52) {
		if (where_are_cards[x] == CPU1_HAND) {
		switch (y) {
			case 0:
				location_of_CPU1_card_1 = x;
				y++;
				break;
			case 1:
				location_of_CPU1_card_2 = x;
				y++;
				break;
			case 2:
				location_of_CPU1_card_3 = x;
				y++;
				break;
		}
		}
		x++;
	}

	x = 0;
	x = 0;

	while (x<52) {
		if (where_are_cards[x] == CPU2_HAND) {
		switch (y) {
			case 0:
				location_of_CPU2_card_1 = x;
				y++;
				break;
			case 1:
				location_of_CPU2_card_2 = x;
				y++;
				break;
			case 2:
				location_of_CPU2_card_3 = x;
				y++;
				break;
		}
		}
		x++;
	}

	x = 0;
	x = 0;

	while (x<52) {
		if (where_are_cards[x] == MIDDLE) {
		switch (y) {
			case 0:
				location_of_middle_card_1 = x;
				y++;
				break;
			case 1:
				location_of_middle_card_2 = x;
				y++;
				break;
			case 2:
				location_of_middle_card_3 = x;
				y++;
				break;
		}
		}
		x++;
	}

	printf("Table:\n");
	printf("  Your hand: "); print_card(pack[location_of_player_card_1]);
	printf("             "); print_card(pack[location_of_player_card_2]);
	printf("             "); print_card(pack[location_of_player_card_3]);

}

void play_game() {
	printf("\nYou will be playing against two computer players.\n");
	printf("Shuffling pack... "); shuffle_pack(); printf("Done!\n");

	int i=0; while (i<52) { where_are_cards[i] = PACK; i++; } //
Initialize where_are_cards[51] array
	i=0; while (i<3) { where_are_cards[i] = PLAYER_HAND; i++; } // Give
player 3 cards
	i=3; while (i<3) { where_are_cards[i] = CPU1_HAND; i++; } // Give CPU1
3 cards
	i=6; while (i<3) { where_are_cards[i] = CPU2_HAND; i++; } // Give CPU2
3 cards
	i=9; while (i<3) { where_are_cards[i] = MIDDLE; i++; } // Put 3 cards
in the middle

	print_card(pack[5]);

	print_stats();
}

int main (int argc, const char * argv[]) {
      printf("Welcome to the game of 31s!\n");
	  printf("This was created by Simon Goldring in 2006.\n");

	  int menu;
	  while ( menu != 1 ) {
	  printf("\nMAIN MENU:\n");
	  printf("  0 - Play a game of 31s with the computer\n");
	  printf("  1 - Quit 31s\n");
	  printf("? ");
	  scanf("%d", &menu);
	  if ( menu == 0 ) {
	  play_game();
	  }
	  }
	  
	  printf("\nThanks for playing!");
	  
      return 0;
}

0
7/18/2006 2:57:15 PM
Simon wrote:

> Thanks, Chris, this is really helpful. I've cleared up stuff you said
> in long-hand just to make sure but it's still not quite working - my
> program, that is. I've commented out a bit in shuffle_cards which
> randomizes but it's still very wierd with all these "signal" errors.

Those are likely array-indexing errors. (You don't get a nice message
when that happens in C - things will go loudly wrong if you're lucky,
quietly wrong if you're unlucky.) 

You should read a decent introductory C book - your previous language
is interfering and you need a bit of reprogramming!

Just a few quick notes at days end:

> void shuffle_pack() {
>       srand(time(0));  // initialize seed "randomly"
>       int i,x,y,z = 0;

Only initialises `z`. `i`, `x`, and `y` are all junk. 

    int i = 0, x = 0, y = 0, z = 0;
or
    int i = 0;
    int x = 0;
    int y = 0;
    int z = 0;


>       int x,y = 0;

Ditto.

> 
>       x = 0;
>       x = 0;

One of those should be `y = 0`?

    x = y = 0;
 
>       x = 0;
>       x = 0;

Ditto.
 
>       x = 0;
>       x = 0;

Ditto.

-- 
Chris "seeker" Dollin
"I'm still here and I'm holding the answers" - Karnataka, /Love and Affection/

0
chris.dollin (1683)
7/18/2006 3:06:19 PM
On 18 Jul 2006 07:57:15 -0700, in comp.lang.c , "Simon"
<SimonGoldring@gmail.com> wrote:

>Thanks, Chris, this is really helpful. I've cleared up stuff you said
>in long-hand just to make sure but it's still not quite working - my
>program, that is. I've commented out a bit in shuffle_cards which
>randomizes but it's still very wierd with all these "signal" errors.
>Here's the complete code:
>	int i,x,y,z = 0;

This only initialises z to zero.  Same problem appears several other
times.

Top tip: do not declare more than one variable on a line;
	int i = 0;
	int x = 0;
that way, you cannot make this sort of mistake. 
(or this one:
	FILE *a, b;
) 


By the way, while some C compilers now allow you to declare variables
where used, most do not - you must declare all variables at the start
of a block. I worry that you are accidentally compiling this code as
C++. 
-- 
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place. 
 Therefore, if you write the code as cleverly as possible, you are, 
 by definition, not smart enough to debug it."
--Brian Kernighan
0
markmcintyre (4555)
7/18/2006 3:43:41 PM
Simon wrote:
[...]
> CARD pack[51];
> int where_are_cards[51];
[...]

Last I checked, there are 52 cards in the deck.

  CARD pack[52];
  int where_are_cards[52];

>        int i,x,y,z = 0;

i, x, and y are not initialized here.

         int i=0, x=0, y=0, z=0;

> 
>         while (x < 4) {
>                 while (y < 13) {
>                         pack[x*y].value = y;
>                         pack[x*y].suit = x;
>                         y++;
>                 }
>                 y = 0;
>                 x++;
>         }

You probably want "pack[x*13+y]" here.

-- 
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody        | www.hvcomputer.com | #include              |
| kenbrody/at\spamcop.net | www.fptech.com     |    <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:ThisIsASpamTrap@gmail.com>

0
kenbrody (1879)
7/18/2006 5:08:53 PM
I'm changing all the initializing stuff, but I don't understand one
thing; doesn't an array tart at 0, so 52 items would be 0-51?

Thanks for all the help.

0
7/18/2006 6:04:55 PM
Simon said:

> I'm changing all the initializing stuff, but I don't understand one
> thing; doesn't an array tart at 0, so 52 items would be 0-51?

Sure, 52 items would be 0-51, but if you define it as being CARD pack[51], 
that's 51 items, 0-50. In an array definition, the number between [ and ] 
is the number of objects you want the array to contain, not the number of 
the highest index in the array.

-- 
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
0
invalid171 (7008)
7/18/2006 6:10:03 PM
aha! Cheers!

0
7/18/2006 6:16:35 PM
Simon wrote:

> aha! Cheers!


Please quote enough of the previous message for context. Google does
this automatically now, so you have no excuse.




Brian
0
defaultuserbr (3656)
7/18/2006 7:34:56 PM
Reply:

Similar Artilces:

I don't work for IBM and I don't make promises I can't deliver on
I wish I could afford an advertising campaign to compete with what they have on the Internet now. I promise to go totally ballistic at the next LLLNL contract. Robert. On 8/12/2011 11:24 PM, Robert Myers wrote: > I wish I could afford an advertising campaign to compete with what they > have on the Internet now. > > I promise to go totally ballistic at the next LLLNL contract. > > Robert. I don't work for IBM (anymore) either. If you are talking about the death of Blue Waters, I don't believe they said they couldn't deliver. They said they chose not to because they would lose a bunch of money on the project since it turned out to cost a lot more than the initial guess. And I guess Ben chose not to print some more to pay for it. On Aug 24, 11:17=A0pm, Del Cecchi <delcec...@gmail.com> wrote: > On 8/12/2011 11:24 PM, Robert Myers wrote: > > > I wish I could afford an advertising campaign to compete with what they > > have on the Internet now. > > > I promise to go totally ballistic at the next LLLNL contract. > > > Robert. > > I don't work for IBM (anymore) either. =A0If you are talking about the > death of Blue Waters, I don't believe they said they couldn't deliver. > They said they chose not to because they would lose a bunch of money on > the project since it turned out to cost a lot more than the initial guess= .. > > And I guess Ben chose not to print some mor...

I sell various items for Amiga on EBAY, if you don't agree don't read and don't break my balls, understand mr. user?
See on this link: http://search.ebay.it/_W0QQsassZmousemikiQQhtZ-1 P.s. not all items are for Amiga, simple don't see others! ...

AOL 9.0 don't do it just don't . Don't even think of it.
I had 8.0, and it ran fine. I downloaded 9.0 and that was the end of my computer never having a problem. 3 years and no problems. 1 week with AOL 9.0 and I've had 27 error messages , sign offs and other problems. AOL was no help. They can't even admit it has a problem. So I had to REFORMAT MY HARD DRIVE AND INSTALL ALL MY PROGRAMS AND ALL MY SAVED FILES. Needless to say I no longer have AOL at all. Reformat and get rid of it. ...

Databases Don't Work With OSes; OSes Don't Work With Databases -- Windos 2003 "You've Made A Mess" Say Irate Users !?!!
http://groups.google.com/groups?q=windows+2003+server+problem&hl=en&lr=&ie=UTF-8&as_drrb=b&as_mind=12&as_minm=2&as_miny=2004&as_maxd=7&as_maxm=6&as_maxy=2004&selm=ObEBOsECEHA.684%40tk2msftngp13.phx.gbl&rnum=1 Search Result 1 From: Dave Verwer (d.verwer@link-hrsystems.com) Subject: Problem with SQL Server & MSDTC on Windows 2003 (dtctester.exe related) View: Complete Thread (9 articles) Original Format Newsgroups: microsoft.public.sqlserver.server, microsoft.public.windows.server.general Date: 2004-03-12 08:02:14 PST Hi all I am not sure if this is a Windows 2003 server problem or a SQL Server problem so I am cross posting to both groups. I have a new Dell server which is running Windows 2003 and is going to be a development database server. I have SQL Server 2000 installed on it and i can connect using the SQL client tools manipulate data on that server without any problems. The problem comes when I try and connect using an ODBC connection from within an MTS/COM+ component. I get the following error: Microsoft OLE DB Provider for ODBC Drivers error '8004d00a' [Microsoft][ODBC SQL Server Driver]Distributed transaction error While searching for a solution to this problem, I came across a Microsoft utility (available from http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q293799) which has helped me narrow this problem down to it not being my COM+ component because when I try and run this tool I get th...

Linux crapware victim: Mepis8 'collapsed'... webcams don't work on Ubuntu 12.04..."Don't tell me to build a kernel..."
"I need my webcam to work with flash on web pages so that I can speak to family members overseas (Kopete and suchlike). I used mepis8 for years and everything was perfect, my webcams (three different makes), printers and anything else I cared to plug in worked from the off. lovely!! Then mepis8 collapsed suddenly and nothing worked. I tried the newer mepis variants and every other linux distro that I came across to solve the problem, but nothing works. I'm now using ubuntu 12.04, because it's not windows I suppose, but it's far from what I need. Can anybody on here please tell me how to make any one of my webcams work on Ubuntu 12.04 with flash? Don't tell me it's the manufacturer's fault, because they worked on Mepis8. Don't tell me to build a kernel and add some Su (or do or sudo) and add a line et al because it's all gibberish to me. Keep it simple please. Complicated is fine as long as it's step by step or copy and paste. Unfortunately, after about 12 years on linux, I will be driven back to windows if I don't get some help. The Mepis forums used to be excellent for advice because there weren't any bigheads showing off their superior knowledge of linux on it. The Ubuntu forums seem to be the opposite, more than 1000 posts (in two threads) on why they prefer ubuntu to xp, but none of them can help me get my webcam working!!!! So this is the challenge, before ...

Don't understand: when('foo' and/or 'bar')
Would someone be so kind to explain the following (quotes are for win32 perl): perl -E" $u='foo'; given($u){ when('foo' and 'bar'){say 'f'} default{say 'd'} } " d perl -E" $u='bar'; given($u){ when('foo' and 'bar'){say 'f'} default{say 'd'} } " f perl -E" $u='baz'; given($u){ when('foo' and 'bar'){say 'f'} default{say 'd'} } " d perl -E" $u='foo'; given($u){ when('foo' or 'bar'){say 'f'} default{...

don't like, so don't waste your time thinking and buy them. You know, if you don't like one thing, it means nothing for you.</p>
<p> I think everyone knows the shoes is apart of our dressing, it can influence our appearance also. Therefore, choose the most suitable shoes for you are very important, than it is obvious that the Nike shoes is the most wonderful shoes for your choice. The Nike Air Max Shoes are new productions that are <a title="Air Force One" href="http://www.nike-airmax-seller.com/">Air Force One</a>pushed out in these years. They are well-sale that so many people affirm them. Here, let Kitty take you to look at some features of the Nike Air Max shoes.</p> <p>huge air max unit waste space and are heavier on the foot, use tiny 1 is going to be lighter and nonetheless generates <br / > </p> <p>2. If the store has some rare Nike shoes in stock, you should go check them out. The looks could be very important because whether you like it or not could decide whether to<a title="Nike Air Max 2011" href="http://www.nike-airmax-seller.com/nike-air-max-2011- c-112.html">Nike Air Max 2011</a> buy them or not. If the looks you don't like, so don't waste your time thinking and buy them. You know, if you don't like one thing, it means nothing for you.</p> http://www.nike-airmax-seller.com ...

IE doesn't work if ZoneAlarm isn't running
I have Release 2.6 of Zonealarm on my laptops. I've found that i have to have ZoneAlarm running to surf the net. If ZoneAlarm is not running I get the page not found message in IE. I can't even receive/send emails via Outlook Express. Is there a setting in ZoneAlarm that does this? > I have Release 2.6 of Zonealarm on my laptops. I've found that i have > to have ZoneAlarm running to surf the net. If ZoneAlarm is not > running I get the page not found message in IE. I can't even > receive/send emails via Outlook Express. Is there a setting in > ZoneAlarm that does this? Try to kill vsmon.exe On 7 Sep 2003 07:23:17 -0700, Vik Mehta wrote: > I have Release 2.6 of Zonealarm on my laptops. I've found that i have > to have ZoneAlarm running to surf the net. If ZoneAlarm is not > running I get the page not found message in IE. I can't even > receive/send emails via Outlook Express. Is there a setting in > ZoneAlarm that does this? Don't try killing vsmon or you'll get no internet access at all. The correct method of stopping ZA is to uncheck the 'Load ZA at startup' option and reboot. Why would you want to 'not run ZA', surely you have it running all the time? There is a more recent version of ZA free that has some upgrades and fixes, you might want to try that. Regards Bill > Don't try killing vsmon or you'll get no internet access at all. The > correct method of stopping ...

Don't ask, don't tell...
While my son visited me for the day, after we went to the Hawks-Giants game and then to see Harry Potter he was still awake (12 years old) and so I put him in front of my Suse 10.0 machine and let him play Unreal Tournament 2004 in Linux. I let him set up the machine in Control Center first (he's a right hander and I'm a leftie), using KDE Control center, and then had him launch and run UT2004. I did't say anything about this being a Linux machine and I have no idea if he knows what Linux is even. I was about to "give the speech about Linux" and I decided, no, I would just let him use the machine and see what he said. He said nothing. He just used the machine as a PC, made the changes, launched an app and played UT04. To me that speaks volumes. That a new user to Linux, who's never seen it in his life, did not perk up and say "oh, what's this! is it some new kind of computer!". No, it was just another GUI, that allowed him to do the task that he wanted to. And that means that there is nothing stopping Linux. John Bailo wrote: > While my son visited me for the day, after we went to the Hawks-Giants game > and then to see Harry Potter he was still awake (12 years old) and so I put > him in front of my Suse 10.0 machine and let him play Unreal Tournament > 2004 in Linux. I let him set up the machine in Control Center first (he's > a right hander and I'm a leftie), using KDE Control center, an...

don't tell don't ask
I'm still struggling with OO concepts. I've read several books and studied various OO languages, but I don't really feel I have a good grasp of the concepts. I like the sound of the "tell, don't ask" model, where networks of objects are asked to perform the work they are responsible for, rather than asking objects to give you information (like a string) that you do something with. But, I get confused when I try to apply the idea to a program design. The only way I can think of avoiding asking objecs for information is if the program consists of nothing but one object of class "Program" with one method called "execute" that does everything. I've seen an example of bad design: AssociativeArray c = object.getEmployees() for each employee in employees: c.put(employee.name(), employee) the "tell don't ask" version of which could be: object.addEmployees(employees); So, "object"'s class supports the "tell model", by allowing you to tell it to add employees rather than asking it for a map to modify. But, doesn't that mean that "employees"'s class has to support the "ask model", so that it "object" can get each of the "employee" objects and their names? Is there a way to actually use "tell" insead of "ask", through out. Or, how do you categorize when you should use "tell" and when you should use "ask"?...

I don't get why '>' doesn't get printed in the following example
When I do a here-document, the '>' character shows up to indicate the start of a newline. [cdalten@localhost ~]$ cat << EOF > My current directory is dir $PWD > EOF My current directory is dir /home/cdalten [cdalten@localhost ~]$ What prevents the '>' characters from showing up in the final output? On Jul 3, 10:35 am, Chad <cdal...@gmail.com> wrote: > When I do a here-document, the '>' character shows up to indicate the > start of a newline. > > [cdalten@localhost ~]$ cat << EOF> My current directory is dir $PWD > &...

i don't understand 'context sensitivity'
============================================================================================== @array = ('a', 'b', 'c'); and ($array[0], $array[1], $array[2]) = ('a', 'b', 'c'); do not do the same thing. The first clears the array, and gives it three elements with the given values; the second changes the values of the first three elements of the array, and leaves the rest alone. ============================================================================================== from http://japhy.perlmonk.org/articles/pm/2000-02.html what is different between @array = ('a', 'b', 'c'); and ($array[0], $array[1], $array[2]) = ('a', 'b', 'c'); ? help me.. On 2011-01-14, Anster wrote: > what is different between > > @array = ('a', 'b', 'c'); > > and > > ($array[0], $array[1], $array[2]) = ('a', 'b', 'c'); > > ? # Begin example 1 my @array = ('q', 'w', 'e', 'r'); print "Before:\n"; print "$_\n" for @array; print "After:\n"; @array = ('a', 'b', 'c'); print "$_\n" for @array; # End example 1 > Before: > q > w > e > r > After: > a > b > c # Begin example 2 my @array = ('q', 'w', 'e', 'r'); print "Before:\n"; print "$_\n" for @ar...

I don't understand why this Swift 2 String() won't init
I have this code in an os x playground (XCode Version 7.2 (7C68)): let urlString = "https://news.google.com" let url = NSURL(string: urlString)! let listData = NSData(contentsOfURL: url)! var dataString = String(data: listData, encoding: NSUTF8StringEncoding) print(dataString) and what seems to me to be equilivent code in an OS X app I'm building: static func httpRequest(urlString: String) -> String { if let url = NSURL(string: urlString) { if let urlData = NSData(contentsOfURL: url) { return String(data: urlData, encoding: NSUTF8StringEncoding) ?? &quo...

I can't understand why the code doesn't seems to function very well
can you help me please because I can't understand why the code doesn't seems to function very well: in onkeypress it must verify if insert number or string value in the fiels, but it doesn't seems to function very well (in frontpage it works but here it doesn't) PROGRAMMA IN FRONTPAGE <form method="get" name="f"> numerico<input type="text" name="t1" onkeypress="return numeralsOnly(event)"/><br/> stringa <input type="text" name="t2" onkeypress="return lettersOnly(event)"/><br/> PROGRAMMA IN PHP <!doctype html public "-//W3C//DTD HTML 4.0 //EN"> <html> <head> <title>Title here!</title> </head> <body> <script type="text/javascript"> function numeralsOnly(evt) { evt = (evt) ? evt : event; var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0)); if (charCode > 31 && (charCode < 48 || charCode > 57)) { alert("Puoi inserire solo numeri!"); return false; } return true; } function lettersOnly(evt) { evt = (evt) ? evt : event; var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0)); if (charCode > 31 && (charCode < 65 || charCode > 90) && (charCode < 97 || charCode > 122)) { alert("Pu...

DTD won't parse, don't understand the error messages
I have (obviously) an error in my DTD. Different parsers give me different error messages, but none of them help me understand the problem or how to fix it. sgmls says 'onsgmls:<URL>http://bowyer.journeyman.cc/adl/stable/adl/ schemas/adl-1.4.dtd:483:27:E: "canonical" is not a reserved name' Xerces says 'http://bowyer.journeyman.cc/adl/stable/adl/schemas/ adl-1.4.dtd:483:28:Parse Error: the attribute type is required in the declaration of the attribute "sequence" for the element "order". What's actually there at 483 is: <!ELEMENT order (documentation?)> <!ATTLIST order property CDATA #REQUIRED sequence %Sequences; #IMPLIED> where Sequences is defined at line 174 as <!-- sequences for orderings of lists - see entity 'order' canonical: Whatever the normal canonical ordering for this datatype is - typically alpha-numeric, except for dates, etc. reverse-canonical: The reverse of the above possibly there should be some further values but I have no idea what these are --> <!ENTITY % Sequences "canonical|reverse-canonical"> Ideally I'd like not only to know how to fix it, but to understand why it's wrong in order that I don't make the same mistake again. Thanks! -- ;; Semper in faecibus sumus, sole profundam variat 20 Jun 2010 14:53:22 GMT, /Simon Brooke/: > Xerces says 'http://bowyer.journe...

isn't the troll, these STUPID guys don't ignore him is problem!!!
-- joerg... ...

FAQ 5.33 Why can't I use "C:\temp\foo" in DOS paths? Why doesn't `C:\temp\foo.exe` work?
This message is one of several periodic postings to comp.lang.perl.misc intended to make it easier for perl programmers to find answers to common questions. The core of this message represents an excerpt from the documentation provided with Perl. -------------------------------------------------------------------- 5.33: Why can't I use "C:\temp\foo" in DOS paths? Why doesn't `C:\temp\foo.exe` work? Whoops! You just put a tab and a formfeed into that filename! Remember that within double quoted strings ("like\this"), the backslash is an escape charact...

FAQ 5.33: Why can't I use "C:\temp\foo" in DOS paths? Why doesn't `C:\temp\foo.exe` work?
This message is one of several periodic postings to comp.lang.perl.misc intended to make it easier for perl programmers to find answers to common questions. The core of this message represents an excerpt from the documentation provided with Perl. -------------------------------------------------------------------- 5.33: Why can't I use "C:\temp\foo" in DOS paths? Why doesn't `C:\temp\foo.exe` work? Whoops! You just put a tab and a formfeed into that filename! Remember that within double quoted strings ("like\this"), the backslash is an escape charact...

FAQ 5.35 Why can't I use "C:\temp\foo" in DOS paths? Why doesn't `C:\temp\foo.exe` work? #5
This is an excerpt from the latest version perlfaq5.pod, which comes with the standard Perl distribution. These postings aim to reduce the number of repeated questions as well as allow the community to review and update the answers. The latest version of the complete perlfaq is at http://faq.perl.org . -------------------------------------------------------------------- 5.35: Why can't I use "C:\temp\foo" in DOS paths? Why doesn't `C:\temp\foo.exe` work? Whoops! You just put a tab and a formfeed into that filename! Remember that within double quoted strings ("like\this"), the backslash is an escape character. The full list of these is in "Quote and Quote-like Operators" in perlop. Unsurprisingly, you don't have a file called "c:(tab)emp(formfeed)oo" or "c:(tab)emp(formfeed)oo.exe" on your legacy DOS filesystem. Either single-quote your strings, or (preferably) use forward slashes. Since all DOS and Windows versions since something like MS-DOS 2.0 or so have treated "/" and "\" the same in a path, you might as well use the one that doesn't clash with Perl--or the POSIX shell, ANSI C and C++, awk, Tcl, Java, or Python, just to mention a few. POSIX paths are more portable, too. -------------------------------------------------------------------- The perlfaq-workers, a group of volunteers, maintain the perlfaq. They are not necessarily e...

FAQ 5.35 Why can't I use "C:\temp\foo" in DOS paths? Why doesn't `C:\temp\foo.exe` work? #10
This is an excerpt from the latest version perlfaq5.pod, which comes with the standard Perl distribution. These postings aim to reduce the number of repeated questions as well as allow the community to review and update the answers. The latest version of the complete perlfaq is at http://faq.perl.org . -------------------------------------------------------------------- 5.35: Why can't I use "C:\temp\foo" in DOS paths? Why doesn't `C:\temp\foo.exe` work? Whoops! You just put a tab and a formfeed into that filename! Remember that within double quoted strings ("like\this"), the backslash is an escape character. The full list of these is in "Quote and Quote-like Operators" in perlop. Unsurprisingly, you don't have a file called "c:(tab)emp(formfeed)oo" or "c:(tab)emp(formfeed)oo.exe" on your legacy DOS filesystem. Either single-quote your strings, or (preferably) use forward slashes. Since all DOS and Windows versions since something like MS-DOS 2.0 or so have treated "/" and "\" the same in a path, you might as well use the one that doesn't clash with Perl--or the POSIX shell, ANSI C and C++, awk, Tcl, Java, or Python, just to mention a few. POSIX paths are more portable, too. -------------------------------------------------------------------- The perlfaq-workers, a group of volunteers, maintain the perlfaq. They are not necessarily ex...

FAQ 5.36 Why can't I use "C:\temp\foo" in DOS paths? Why doesn't `C:\temp\foo.exe` work? #3
This is an excerpt from the latest version perlfaq5.pod, which comes with the standard Perl distribution. These postings aim to reduce the number of repeated questions as well as allow the community to review and update the answers. The latest version of the complete perlfaq is at http://faq.perl.org . -------------------------------------------------------------------- 5.36: Why can't I use "C:\temp\foo" in DOS paths? Why doesn't `C:\temp\foo.exe` work? Whoops! You just put a tab and a formfeed into that filename! Remember that within double quoted strings ("like\this"), the backslash is an escape character. The full list of these is in "Quote and Quote-like Operators" in perlop. Unsurprisingly, you don't have a file called "c:(tab)emp(formfeed)oo" or "c:(tab)emp(formfeed)oo.exe" on your legacy DOS filesystem. Either single-quote your strings, or (preferably) use forward slashes. Since all DOS and Windows versions since something like MS-DOS 2.0 or so have treated "/" and "\" the same in a path, you might as well use the one that doesn't clash with Perl--or the POSIX shell, ANSI C and C++, awk, Tcl, Java, or Python, just to mention a few. POSIX paths are more portable, too. -------------------------------------------------------------------- The perlfaq-workers, a group of volunteers, maintain the perlfaq. They are not necessarily ex...

FAQ 5.35 Why can't I use "C:\temp\foo" in DOS paths? Why doesn't `C:\temp\foo.exe` work? #9
This is an excerpt from the latest version perlfaq5.pod, which comes with the standard Perl distribution. These postings aim to reduce the number of repeated questions as well as allow the community to review and update the answers. The latest version of the complete perlfaq is at http://faq.perl.org . -------------------------------------------------------------------- 5.35: Why can't I use "C:\temp\foo" in DOS paths? Why doesn't `C:\temp\foo.exe` work? Whoops! You just put a tab and a formfeed into that filename! Remember that within double quoted strings ("like\this"), the backslash is an escape character. The full list of these is in "Quote and Quote-like Operators" in perlop. Unsurprisingly, you don't have a file called "c:(tab)emp(formfeed)oo" or "c:(tab)emp(formfeed)oo.exe" on your legacy DOS filesystem. Either single-quote your strings, or (preferably) use forward slashes. Since all DOS and Windows versions since something like MS-DOS 2.0 or so have treated "/" and "\" the same in a path, you might as well use the one that doesn't clash with Perl--or the POSIX shell, ANSI C and C++, awk, Tcl, Java, or Python, just to mention a few. POSIX paths are more portable, too. -------------------------------------------------------------------- The perlfaq-workers, a group of volunteers, maintain the perlfaq. They are not necessarily ex...

FAQ 5.35 Why can't I use "C:\temp\foo" in DOS paths? Why doesn't `C:\temp\foo.exe` work? #6
This is an excerpt from the latest version perlfaq5.pod, which comes with the standard Perl distribution. These postings aim to reduce the number of repeated questions as well as allow the community to review and update the answers. The latest version of the complete perlfaq is at http://faq.perl.org . -------------------------------------------------------------------- 5.35: Why can't I use "C:\temp\foo" in DOS paths? Why doesn't `C:\temp\foo.exe` work? Whoops! You just put a tab and a formfeed into that filename! Remember that within double quoted strings ("like\this"), the backslash is an escape character. The full list of these is in "Quote and Quote-like Operators" in perlop. Unsurprisingly, you don't have a file called "c:(tab)emp(formfeed)oo" or "c:(tab)emp(formfeed)oo.exe" on your legacy DOS filesystem. Either single-quote your strings, or (preferably) use forward slashes. Since all DOS and Windows versions since something like MS-DOS 2.0 or so have treated "/" and "\" the same in a path, you might as well use the one that doesn't clash with Perl--or the POSIX shell, ANSI C and C++, awk, Tcl, Java, or Python, just to mention a few. POSIX paths are more portable, too. -------------------------------------------------------------------- The perlfaq-workers, a group of volunteers, maintain the perlfaq. They are not necessarily e...

FAQ 5.35 Why can't I use "C:\temp\foo" in DOS paths? Why doesn't `C:\temp\foo.exe` work? #4
This is an excerpt from the latest version perlfaq5.pod, which comes with the standard Perl distribution. These postings aim to reduce the number of repeated questions as well as allow the community to review and update the answers. The latest version of the complete perlfaq is at http://faq.perl.org . -------------------------------------------------------------------- 5.35: Why can't I use "C:\temp\foo" in DOS paths? Why doesn't `C:\temp\foo.exe` work? Whoops! You just put a tab and a formfeed into that filename! Remember that within double quoted strings ("like\this"), the backslash is an escape character. The full list of these is in "Quote and Quote-like Operators" in perlop. Unsurprisingly, you don't have a file called "c:(tab)emp(formfeed)oo" or "c:(tab)emp(formfeed)oo.exe" on your legacy DOS filesystem. Either single-quote your strings, or (preferably) use forward slashes. Since all DOS and Windows versions since something like MS-DOS 2.0 or so have treated "/" and "\" the same in a path, you might as well use the one that doesn't clash with Perl--or the POSIX shell, ANSI C and C++, awk, Tcl, Java, or Python, just to mention a few. POSIX paths are more portable, too. -------------------------------------------------------------------- The perlfaq-workers, a group of volunteers, maintain the perlfaq. They are not necessarily e...

Web resources about - Don't understand why my code isn't working - comp.lang.c

Resonate Social For Facebook Helps Advertisers Understand Users’ Motivations
Why do Facebook users make the decisions they make? Resonate wants to help advertisers find out, so the digital marketing outfit launched Resonate ...

Facebook PMD Gigya releases Consumer Insights to better understand user identities
... allows marketers to easily query Gigya’s Identity Storage database and tie identity information with key performance indicators to understand ...

Genius by Rap Genius — Search and understand the meaning of song lyrics, poetry, literature, and news ...
Get Genius by Rap Genius — Search and understand the meaning of song lyrics, poetry, literature, and news on the App Store. See screenshots and ...

All sizes - Understand Abundance & Breath - Flickr - Photo Sharing!
Flickr is almost certainly the best online photo management and sharing application in the world. Show off your favorite photos and videos to ...

Kate Micucci & Tony Thaxton - "Puppets Understand" - YouTube
Subscribe for more Nerdist Presents: http://nerdi.st/subscribe Written and Performed by KATE MICUCCI & TONY THAXTON Watch Duo: http://youtu.be/Tj5RLliHNMQ ...

Scientists continue search to understand Mers
The Mers coronavirus continues to confound scientists. To better understand the disease and determine where it comes from, a new project set ...

Explainer Video of the Day: Author John Green Helps You Understand Boko Haram
... in the news, but the situation in Nigeria with the Islamist terrorist group Boko Haram often gets overlooked and can be difficult to understand. ...

David Lawton says MH370 disappearance 'hard to understand'
The family of missing Queensland couple Bob and Cathy Lawton are continuing to hold out hope, following a week of confusion and twists in the ...

12 Words And Phrases Only Accountants Will Understand
Every industry has its own set of jargon.

Tony Abbott doesn't understand the China challenge
The Australian government's new attitude towards China's foreign policy underestimates that country's determination to change the geopolitical ...

Resources last updated: 3/30/2016 9:39:52 AM