Unhandled exception at 0x77bf158e in Rawr.exe: 0xC0000005: Access violation.
Jan 22, 2011 at 11:48pm UTC
I'm trying to write a program for class and I keep getting this error message. I'm pretty new to writing in C, but my program will compile fine, but when I go to debug it I get the error
"Unhandled exception at 0x77bf158e in Rawr.exe: 0xC0000005: Access violation."
and theres an arrow pointing towards the line "generateCard(deck)". I'm using Visual Studio 2008. Thanks for the help.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
// Rawr.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "stdlib.h"
#define TRUE 1
#define FALSE 0
void generateCard (int deck[]);
void printArray (int deck[]);
int _tmain(int argc, _TCHAR* argv[])
{
int seed;
int deck[52]={0};
printf("Enter a seed #, 0 to terminate: " );
scanf("%d" ,&seed);
srand(seed);
while (seed>0)
{
generateCard(deck);
printArray(deck);
}
return 0;
}
void generateCard (int deck[])
{
int i=0,x,j=0,uniq=TRUE;
deck[0]=rand()%52;
while (i<52)
{
x=rand()%52;
while (uniq&&j<=1)
{
if (x==deck[j])
{
uniq=FALSE;
j++;
}
if (uniq)
{
i++;
deck[i]=x;
}
}
}
}
void printArray (int deck[])
{
int j,counter=1,seed;
for (j=0;j<52;j++)
{
printf("%5d" ,deck[j]);
counter++;
if (counter%13==0)
printf("\n" );
}
printf("Enter a seed #, 0 to terminate: " );
scanf("%d" ,&seed);
}
Trying to get 52 unique random numbers into an array, to simulate a deck of cards being dealt.
Last edited on Jan 23, 2011 at 4:57am UTC
Topic archived. No new replies allowed.