GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 12-May-2004, 12:19
moltarim moltarim is offline
New Member
 
Join Date: May 2004
Posts: 3
moltarim is on a distinguished road
Post

newbie with pointer problems.


i am having a problem with two of the functions in a wave program i am trying to construct. the function current wave is supposed to display the current/last wave in the graphics window but unfortunately it only ever displays the first wave. the function summation wave suffers from the same problem. i believe this is due to bad use of pointers but it may also be down to the if else statements i have used within the functions. any help with this problem would be greatly appreciated..
Attached Files
File Type: txt waves.txt (7.4 KB, 19 views)
  #2  
Old 14-May-2004, 10:46
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Quote:
Originally Posted by moltarim
i am having a problem with two of the functions in a wave program i am trying to construct. the function current wave is supposed to display the current/last wave in the graphics window but unfortunately it only ever displays the first wave. the function summation wave suffers from the same problem. i believe this is due to bad use of pointers but it may also be down to the if else statements i have used within the functions. any help with this problem would be greatly appreciated..

Hi Moltarim. I am so sorry that i haven't gotten to this sooner. I have been so busy with other things. I do see that you have used some of my advice in your code. You are definitely having some pointer (or linked list) problems. I am assuming that all of your data is inserting correctly though.

For example here:

CPP / C++ / C Code:
void draw_wave() // function used to draw waves
{
    int i;
    double a,b,angleC,radianC,degrees;
    double  omega,vert[600];

    if(!head)    //Go to last position in list
    {
	current=current->next;

I am not sure what you are trying to do.

if head is null than there is no data in the list and you should not even try to access it after that!

Then later, you have:

CPP / C++ / C Code:
else
	{
	   current=head;

Which is simply assigning the current position to the top of the list every time.

Your summation routine is having the exact same problem, so you are always printing/summing only the first wave. The way that this is set up is that current should be always pointing at the "current" location. This "current" location is changed in your main switch function here:

CPP / C++ / C Code:
case 'h':
        current = head;
        if(current)
	{
          printf("\nCurrent Wave is:\n");
          list_current();
        }
        break;

      case 'n':
        if(current)
	{
          if(current->next)
            current = current->next;
            printf("\nCurrent Wave is:\n");
        }
        list_current();
        break;

The first will position the current at the head of the list, the next one will index down the list one at a time.

So when you enter these functions (draw_wave & summation_wave) the only thing you should check for is that current is actually pointing to something, by simply saying.

CPP / C++ / C Code:
if(current){
...
}

Hope this isn't too late to help you out. I should have looked at this sooner. I just got to busy with other things.

Good luck,
d
 
 

Recent GIDBlogProgramming ebook direct download available by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Basic pointer problems Trust C Programming Language 1 09-May-2004 07:07
Chaintech Geforce 5600 FX problems bartster74 Computer Hardware Forum 8 04-May-2004 14:16
Please Help, problems writing newbie c program soulfly C Programming Language 14 04-Mar-2004 16:16
Please Help, problems writing newbie C program ReREVISED soulfly C Programming Language 0 02-Mar-2004 23:01
convert long to pointer to char realpopeye C++ Forum 2 26-Sep-2003 11:22

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 00:31.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.