Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 04-12-2003, 11:26 AM   #1 (permalink)
Goshi
Registered User
 
Join Date: Apr 2003
Location: Fresno, CA
Posts: 4
Goshi is on a distinguished road
Send a message via AIM to Goshi
structure problem

First off, I am not a programmer. I'm in a Geomatics Engineering program that requires us to have some basic programming knowledge. I'll be gratefull for any help I get here, but please dumb it down as much as possible.

Ok, here is my problem:
I am trying to pass an array inside a structure, inside my function I assign some data that I need to use in my main. This is the part where I assign data to the array (this is from inside a loop):

if(cfflag = 1)
{
current.cut[m] = area;
++m;
}

I am currently trying to debug this and in my main function, immediately following the function containing the above code, I find the value is 0, not whatever it was just assigned to be.

I am not that good at this stuff and it's probably something stupid. I don't even know if it's ok to make sturctures this way:

typedef struct AREA
{
double sta;
double cut[10]; // <- can I do this?
double fill[10];

}AREA;

God I hope this makes sense to someone. I can post more of my code if it will help.

Thanks
Ian

edit:

here is the function call and declaration, etc:

call in main:
area_coords(stablk, blksize, &current);

header:
void area_coords(DATA stablk[100], int blksize, AREA current);
Goshi is offline   Reply With Quote
Old 04-12-2003, 03:51 PM   #2 (permalink)
Unicorn
Registered User
 
Unicorn's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 11
Unicorn is on a distinguished road
Yes, it is possible to use an array inside a struct like that. But if you want to test if cfflag equals one, you should use '==' instead of '='.

Maybe if you post the relevant parts of main() and the body of area_coords(), we can take a closer look.
Unicorn is offline   Reply With Quote
Old 04-13-2003, 05:00 PM   #3 (permalink)
Goshi
Registered User
 
Join Date: Apr 2003
Location: Fresno, CA
Posts: 4
Goshi is on a distinguished road
Send a message via AIM to Goshi
Sure...

MAIN:

posb=0;posa=0,pts=0, totalpts=0;
while(pts<nptsa+nptsb)
{
blksize = 0;
// Extract stationing into temporary block
exrtact_sta(b, a, stablk, &posb, &posa, &blksize);
pts+= blksize;

// Calc area of cut and fill for the chunk
for(i=0;i<10;++i) //initialize
{
current.cut[i]=0;
current.fill[i]=0;
}
cut=0;fill=0;
area_coords(stablk, blksize, current); //calcs the areas of cut/fill
for(i=0;i<10;++i)
{
cut += current.cut[i];
fill += current.fill[i]=0;
}

// Move current station area data to previous (for computation of next volume)
previous.sta = current.sta;
for(i=0;i<10;++i)
{
previous.cut[i]=0;
previous.fill[i]=0;
}
for(i=0;i<10;++i)
{
previous.cut[i] = current.cut[i];
previous.fill[i] = current.fill[i];
}


}//end for loop





FUNCTION:

void area_coords(DATA stablk[100], int blksize, AREA current)
{
double area, one, two;
int i, j, k, m, n, cfflag;

one=0; two=0, j=0, k=0, m=0,n=0;

// Find first inflection point and calc area to second inflection point
for(i=0;i<blksize;++i)
{
if(stablk[i].flag1==0 && stablk[i].flag2==0)
{
j=i;
if(stablk[i+1].z1>stablk[i+1].z2)
cfflag=1;
else if(stablk[i+1].z1<stablk[i+1].z2)
cfflag=0;

one += stablk[j].off * stablk[j+1].z1;
two += stablk[j+1].off * stablk[j].z1;
++j;
while(stablk[j].flag1!=0 && stablk[j].flag2!=0)
{
one += stablk[j].off * stablk[j+1].z1;
two += stablk[j+1].off * stablk[j].z1;
++j;
}
k=j;
while(j>i)
{
one += stablk[j].off * stablk[j-1].z2;
two += stablk[j-1].off * stablk[j].z2;
--j;
}
area=(one-two)/2;
if(area<0)
area=area*-1;
// Determine if area goes to cut or fill
current.sta = stablk[i].sta;
if(cfflag == 1)
{
current.cut[m] = area;
++m;
}
if(cfflag == 0)
{
current.fill[n] = area;
++n;
}
i=k;
}
// Update i to start calcing area from next infelction point
}
}
Goshi is offline   Reply With Quote
Old 04-13-2003, 08:26 PM   #4 (permalink)
palin
Code Monkey
 
palin's Avatar
 
Join Date: Jan 2003
Posts: 57
palin is on a distinguished road
The problem that I see is that you are passing the struct by value. You need to pass by reference.

ie struct_name* _name_
then when you access the struct in the function you need to use pointer reference

_name_->structmember

you might want to read up on that. If I'm wrong someone can correct me.
palin is offline   Reply With Quote
Old 04-14-2003, 03:55 AM   #5 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,693
redhead is on a distinguished road
yup you're right Palin, the way the structs are used now, will only make them accessible during the scope of the function, meaning once teh function has been called, the memory used by it can't be reached from the struct parsed to the functioncall.

So use a reference to the struct.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 04-21-2003, 12:19 AM   #6 (permalink)
Goshi
Registered User
 
Join Date: Apr 2003
Location: Fresno, CA
Posts: 4
Goshi is on a distinguished road
Send a message via AIM to Goshi
Thanks guys

It was a structure problem like my friend suggested it might be and was pointed out here.
Goshi is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Implementing C++ file structure in C# IAmWeasel MS Technologies ( ASP, VB, C#, .NET ) 1 07-08-2004 07:38 AM
JavaScript Problem dawkim HTML, XML, Javascript, AJAX 2 01-26-2004 07:02 PM
strange posting problem on my website......... trevor PHP 2 12-19-2003 12:25 PM
Help debugging a power problem Belisarius Lounge 0 10-25-2003 04:44 PM
This is a windows/C problem UnderWing Standard C, C++ 6 03-28-2003 06:17 AM


All times are GMT -8. The time now is 04:14 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting