473,548 Members | 2,716 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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<iostre am>
#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*size of(long));

for(int radix=0;radix< sizeof(*a);radi x++)
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];
}

May 29 '06 #1
7 2215
al******@gmail. com 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<iostre am>


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

.... snip code ...

May 29 '06 #2
al******@gmail. com 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<iostre am>
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)
May 29 '06 #3
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.cp p : Defines the entry point for the console
application.
//

#include "stdafx.h"
#include<iostre am>
#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*size of(long));

for(int radix=0;radix< sizeof(*a);radi x++)
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++,c p++)
*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.

May 29 '06 #4
In article <11************ **********@g10g 2000cwb.googleg roups.com>,
<al******@gmail .com> wrote:
Well i have made the following changes.But still its not [...]


.... a C program

Try a C++ newsgroup.

-- Richard
May 29 '06 #5
al******@gmail. com 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.cp p : Defines the entry point for the console
application.
//

#include "stdafx.h"
#include<iostre am>
#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.

May 29 '06 #6
On 29 May 2006 07:20:33 -0700, al******@gmail. com 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
May 29 '06 #7
Thanks friends.
finally i got my answer. :-)

May 29 '06 #8

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

Similar topics

1
2589
by: kaiwing18 | last post by:
Hi , I have a problem relate to java and database. Could anyone answer me ?Please see the following code. import java.sql.*; public class Result { public static void main(String args) {
7
2371
by: Alan Bashy | last post by:
Please, guys, In need help with this. It is due in the next week. Please, help me to implement the functions in this programm especially the first three constructor. I need them guys. Please, help me. This was inspired by Exercise 7 and Programming Problem 8 in Chapter 3 of our text. I have done Exercise 7 for you: Below you will find the...
6
3137
by: Daniel Rimmelzwaan | last post by:
I want to send a biztalk document to an aspx page, and I need to see some sample code, because I just can't make it work. I have a port with transport type HTTP, pointing to my aspx page, something like http://myserver/mypage.aspx. From there it gets blurry, because I just can't figure out how to do the rest. Does anybody have a sample page...
2
1567
by: James Zhuo | last post by:
Hi all I've been getting the following compilation error. I should explain the background of the project that i am taking over. This is a project that has been developed by someone else a while ago using dreamweaver, I am basically trying to migrate the project into a Visual Studio .NET environment before I
1
9599
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej and I was wondering if anyone here would be able to give me some tips for young players such as myself, for learning the language. Is this the...
5
346
by: alankrit | last post by:
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>
0
2013
by: raa abdullah | last post by:
Overview A conflict-serializbility\recoverability checker, SCR, is a program that takes in a schedule and outputs 2 decisions: Conflict serialzable or Not confilict serializable AND Recoverable or Not recoverable. The following is a detailed description of the program. Input The input to SCR should be a schedule of operations. It should be in...
6
2260
by: fido19 | last post by:
Once upon a time, there lived a chimpanzee called Luycha Bandor (aka Playboy Chimp). Luycha was unhappily married to Bunty Mona, a short but cute little lady chimp. Luycha was tall and handsome – he was feeling uncomfortable taking Bunty to public places along with him. People would stare at them all the while. At one point, Luycha could not...
0
7518
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7444
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7711
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. ...
0
7954
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...
1
5367
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...
0
5085
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...
0
3478
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1932
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
0
755
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.