473,324 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Need Help in C or C++

5
hi,
we have written a program in VC++ using arrays .The program is just basic C,but since the array size is too big we are unable to run the program so it is a must to use pointers .We also tried using malloc but it is giving us a lot of errors .Can anybody help us please.....
P.S.: We are using a library called free image so there will be some library functions used for gettin some functions like bits per pixel, height of the image and stuff like that so dont worry about that just help me out in the main program tats just basic C.


// Finding the bits per pixel
WORD bpp = FreeImage_GetBPP(dib);

// Finding width and height of the image
int width = FreeImage_GetWidth(dib);
int height = FreeImage_GetHeight(dib);

int n, b[1024], l, i, j, a[1024][1024],
p[1024],t,muT=0,totvar=0,mut[1024],
w0[1024],w1[1024],m0[1024],m1[1024],
a12[1024],
betvar[1024],e[1024],emax,tmax=0;
n=width*height;

for(l=0;l<=(pow(2,bpp))-1;l++)
{
for(i=0;i<=width-1;i++)
{
for(j=0;j<=height-1;j++)
{
if(a[i][j]==l)
b[l]++;
}
}
printf("%d",&b[l]);
}

for(i=0;i<=(pow(2,bpp))-1;i++)
{
p[i]=b[i]/n;
}

for(i=0;i<=(pow(2,bpp))-1;i++)
{
muT+=i*p[i];
}

for(i=0;i<=(pow(2,bpp))-1;i++)
{
totvar+=pow((i-muT),2)*p[i];
}

for(t=0;t<=(pow(2,bpp))-1;t++)
{
for(i=0;i<=t;i++)
{
mut[i]+=i*p[i];
}
for(i=0;i<=t;i++)
{
w0[i]+=p[i];
}

w1[t]=1-w0[t];
m0[t]=mut[t]/w0[t];
m1[t]=(muT-mut[t])/w1[t];
betvar[t]=w0[t]*w1[t]*pow((m1[t]*m0[t]),2);
e[t]=betvar[t]/totvar;
}

emax=e[0];

for(i=1;i<=(pow(2,bpp))-1;i++)
{
if(e[i]>emax)
{
emax=a12[i];
tmax=i;
}
}

printf("Optimal Threshold=%d",&tmax);
Jan 23 '07 #1
2 1209
willakawill
1,646 1GB
Hi. In c++ you use the new operator to allocate array memory space on the heap combined with the delete operator. Also you might find it easier to use single dimension arrays with the following notation
ar[1][2] is the same as ar[1 + (columns * 2)] where columns is the number of elements in the first dimension e.g.
Expand|Select|Wrap|Line Numbers
  1. int a;
  2. int b[3][4];
  3. int a = b[2][3];
would be
Expand|Select|Wrap|Line Numbers
  1. int a;
  2. int b[3*4];
  3. int a = b[2 + (3 * 3)];
in your case:
Expand|Select|Wrap|Line Numbers
  1. long arCols = 1024L;
  2. long arRows = 1024L;
  3. long ar*;
  4. ar = new long[arCols * arRows];
and you access the elements
Expand|Select|Wrap|Line Numbers
  1. long x;
  2.  
  3. x = ar[23 + (arCols * 105)];
To clean up at the end of your proc

Expand|Select|Wrap|Line Numbers
  1. delete [] ar;
Expand|Select|Wrap|Line Numbers
  1. a[i][j];
would be
Expand|Select|Wrap|Line Numbers
  1. a[i + (arCols * j)];
Jan 23 '07 #2
horace1
1,510 Expert 1GB
your arrays appear to be local variables (defined within a function) - try making them global
Jan 23 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Sofia | last post by:
My name is Sofia and I have for many years been running a personals site, together with my partner, on a non-profit basis. The site is currently not running due to us emigrating, but during its...
6
by: Robert Maas, see http://tinyurl.com/uh3t | last post by:
System login message says PHP is available, so I tried this: http://www.rawbw.com/~rem/HelloPlus/h.php It doesn't work at all. Browser just shows the source. What am I doing wrong?
0
by: Gregory Nans | last post by:
hello, i need some help to 'tree-ify' a string... for example i have strings such as : s = """A(here 's , B(A ) silly test) C(to show D(what kind) of stuff i need))""" and i need to...
7
by: Mike Kamermans | last post by:
I hope someone can help me, because what I'm going through at the moment trying to edit XML documents is enough to make me want to never edit XML again. I'm looking for an XML editor that has a...
8
by: JustSomeGuy | last post by:
I need to write an new class derived from the list class. This class stores data in the list to the disk if an object that is added to the list is over 1K in size. What methods of the std stl...
3
by: Bob.Henkel | last post by:
I write this to tell you why we won't use postgresql even though we wish we could at a large company. Don't get me wrong I love postgresql in many ways and for many reasons , but fact is fact. If...
2
by: Michael R. Pierotti | last post by:
Dim reg As New Regex("^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$") Dim m As Match = reg.Match(txtIPAddress.Text) If m.Success Then 'No need to do anything here Else MessageBox.Show("You need to enter a...
8
by: skumar434 | last post by:
i need to store the data from a data base in to structure .............the problem is like this ....suppose there is a data base which stores the sequence no and item type etc ...but i need only...
11
by: Alan Mailer | last post by:
A project I'm working on is going to use VB6 as a front end. The back end is going to be pre-existing MS Access 2002 database tables which already have records in them *but do not have any...
0
by: U S Contractors Offering Service A Non-profit | last post by:
Brilliant technology helping those most in need Inbox Reply U S Contractors Offering Service A Non-profit show details 10:37 pm (1 hour ago) Brilliant technology helping those most in need ...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.