Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > PLease help me.Wots the problem with following code....?

Reply
Thread Tools

PLease help me.Wots the problem with following code....?

 
 
alankrit@gmail.com
Guest
Posts: n/a
 
      05-29-2006
Helo
This is a code for Radix sort. n it is giving a run-time Error :
"Run-Time Check Failure #2 - Stack around the variable 'count' was
corrupted."

I have cross checked this code a millions of times.
what is the problem here..??????????????????

#include "stdafx.h"
#include<iostream>
#include<stdlib.h>

using namespace std;

#define CHAR_BIT 8
#define UCHAR_MAX 0xff
#define RANGE ((1U << CHAR_BIT)+1)
#define digit(x,i) ( (x) >> ( (i) * CHAR_BIT) ) & UCHAR_MAX
#define SIZE 100

void radixsort(long *a, long );
void radixpass(long *a, long *aux, long , int radix);
void makerandom(long *a, long );


int _tmain(int argc, _TCHAR* argv[])
{
long data[SIZE];
makerandom(data,SIZE);

radixsort(data,SIZE);

for(int i=0;i<SIZE;i++)
cout<<data[i]<<"\n";

return 0;
}

void makerandom(long *a,long N)
{
for(int i=0;i<N;i++)
a[i]=rand();
}

void radixsort(long *a,long N)
{
long *aux=(long *)malloc(N*sizeof(long));

for(int radix=0;radix< sizeof(*a);radix++)
radixpass(a,aux,SIZE,radix);

free(aux);
}

void radixpass(long *a,long *aux, long N, int radix)
{
long count[RANGE];
long *cp=count;

for(int i=0;i<RANGE;i++,cp++)
*cp=0;

for(int i=0;i<N;i++)
count[ digit( a[i], radix ) +1 ]++;

for(int i=0;i< RANGE;i++)
count[i+1]+=count[i];

for(int i=0;i<N;i++)
aux[ count[digit(a[i],radix)]++ ]=a[i];

for(int i=0;i<N;i++)
a[i]=aux[i];
}

 
Reply With Quote
 
 
 
 
santosh
Guest
Posts: n/a
 
      05-29-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Helo
> This is a code for Radix sort. n it is giving a run-time Error :

.... snip ...

> #include "stdafx.h"


This is a non-standard header. This group discusses ISO standard
compliant C programs.

> #include<iostream>


This is a C++ header. This group is for C only. Post to comp.lang.c++.

.... snip code ...

 
Reply With Quote
 
 
 
 
Richard Heathfield
Guest
Posts: n/a
 
      05-29-2006
(E-Mail Removed) said:

> Helo
> This is a code for Radix sort. n it is giving a run-time Error :
> "Run-Time Check Failure #2 - Stack around the variable 'count' was
> corrupted."
>
> I have cross checked this code a millions of times.
> what is the problem here..??????????????????
>
> #include "stdafx.h"


Non-standard header.

> #include<iostream>


Non-standard header.

> #include<stdlib.h>
>
> using namespace std;


Syntax error.

> #define CHAR_BIT 8
> #define UCHAR_MAX 0xff


See <limits.h>

> #define RANGE ((1U << CHAR_BIT)+1)
> #define digit(x,i) ( (x) >> ( (i) * CHAR_BIT) ) & UCHAR_MAX


You do realise that + has a higher precedence than &, don't you? Use more
parentheses.

> #define SIZE 100
>
> void radixsort(long *a, long );
> void radixpass(long *a, long *aux, long , int radix);
> void makerandom(long *a, long );
>
>
> int _tmain(int argc, _TCHAR* argv[])


There seems little point in continuing this analysis, since you don't appear
to have done the minimal research necessary to learn how C defines the
entry point to a program.

--
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)
 
Reply With Quote
 
alankrit@gmail.com
Guest
Posts: n/a
 
      05-29-2006
Well i have made the following changes.But still its not working,
giving the same run-time error.

and header files are all correct.

// Radix_Sort_1.cpp : Defines the entry point for the console
application.
//

#include "stdafx.h"
#include<iostream>
#include<stdlib.h>

using namespace std;


#define digit(x,i) (( (x) >> ( (i) * 8 ) ) & 0xff )
#define SIZE 100

void radixsort(long *a, long );
void radixpass(long *a, long *aux, long , int radix);
void makerandom(long *a, long );


int _tmain(int argc, _TCHAR* argv[])
{
long data[SIZE];
makerandom(data,SIZE);

radixsort(data,SIZE);

for(int i=0;i<SIZE;i++)
cout<<data[i]<<"\n";

return 0;
}

void makerandom(long *a,long N)
{
for(int i=0;i<N;i++)
a[i]=rand();
}

void radixsort(long *a,long N)
{
long *aux=(long *)malloc(N*sizeof(long));

for(int radix=0;radix< sizeof(*a);radix++)
radixpass(a,aux,N,radix);

free(aux);
}

void radixpass(long *a,long *aux, long N, int radix)
{
long count[257];
long *cp=count;

for(int i=0;i<257;i++,cp++)
*cp=0;

for(int i=0;i<N;i++)
count[ digit( a[i], radix ) +1 ]++;

for(int i=0;i< 257;i++)
count[i+1]+=count[i];

for(int i=0;i<N;i++)
aux[ count[digit(a[i],radix)]++ ]=a[i];

for(int i=0;i<N;i++)
a[i]=aux[i];
}


Syntax error.

> #define CHAR_BIT 8
> #define UCHAR_MAX 0xff


Hey BTW i dont how to use these constants.Cud u plz temme how to use
it?
thanks.

 
Reply With Quote
 
santosh
Guest
Posts: n/a
 
      05-29-2006
(E-Mail Removed) wrote:
> Well i have made the following changes.But still its not working,
> giving the same run-time error.
>
> and header files are all correct.
>
> // Radix_Sort_1.cpp : Defines the entry point for the console
> application.
> //
>
> #include "stdafx.h"
> #include<iostream>
> #include<stdlib.h>


You're repeatedly posting non-C code. This group only discusses
standard C. I suggest that you post to a C++ group like comp.lang.c++
or better yet, a group devoted for your particular platform. If I'm
right, this is a Windows program. Post to a group in the
comp.os.ms-windows.* hierarchy.
.... snip code ...

> Hey BTW i dont how to use these constants.Cud u plz temme how to use it?


If you need to learn the rudimentary usage of variables and constants a
good text on ISO C or C++ programming will be more suitable than asking
questions here and waiting for a response.

Study and work through a book like "The C Programming Langauge 2 Ed.",
and if you encounter problems within specific areas, you can post here.

 
Reply With Quote
 
Richard Tobin
Guest
Posts: n/a
 
      05-29-2006
In article <(E-Mail Removed) .com>,
<(E-Mail Removed)> wrote:

>Well i have made the following changes.But still its not [...]


.... a C program

Try a C++ newsgroup.

-- Richard
 
Reply With Quote
 
Barry Schwarz
Guest
Posts: n/a
 
      05-29-2006
On 29 May 2006 07:20:33 -0700, (E-Mail Removed) wrote:

>Well i have made the following changes.But still its not working,
>giving the same run-time error.


Please post C++ questions to a C++ group. This group deals only with
C.


Remove del for email
 
Reply With Quote
 
codergem
Guest
Posts: n/a
 
      05-29-2006
Thanks friends.
finally i got my answer.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
The Web server reported the following error when attempting to create or open the Web project located at the following URL: 'http://localhost/822319ev1'. 'HTTP/1.1 500 Internal Server Error'. chanmm ASP .Net 2 09-07-2010 07:37 AM
Dual boot help please - 32bit following XP64 me@tarquin.demon.co.uk Windows 64bit 25 08-09-2006 02:31 AM
PLease help me.Wots the problem with following code....? alankrit@gmail.com C++ 5 05-30-2006 12:02 AM
RE: The Web server reported the following error when attempting to create or open the Web project located at the following URL: <URL> =?Utf-8?B?VHJldm9yIEJlbmVkaWN0IFI=?= ASP .Net 0 06-07-2004 07:36 AM
please help... ...me learn C++ please please please :) KK C++ 2 10-14-2003 02:08 PM



Advertisments