![]() |
| | #1 |
| Registered User Join Date: Jun 2008 Location: Northern Va
Posts: 18
| Code: typedef struct{
double val;
int freq;
}hPoint;
...
...
...
hPoint **momentBin;
momentBin = (void *)malloc(sizeof(hPoint *) * 10);int maxIndex =10;
...
found=0;
for(k=0;k<maxIndex;k++)
{
if(momentBin[k]==NULL)
break;
test =(momentBin[k])->val;
if (test==bN)
{
found =1;
(momentBin[k])->freq++;
break;
};
}
if(found ==0)
{
probCounter++;
//increase the size of the array
if (probCounter>=maxIndex)
{
hPoint **newArr = realloc(momentBin, maxIndex*2);
if (newArr==NULL)
{
printf("Reallocation Error");exit(0);
}
else momentBin = newArr;
};
hPoint *temp =(hPoint *) malloc(sizeof(hPoint));
temp->val=bN;
temp->freq=1;
momentBin[probCounter] = temp;
Thanks |
| firetheGlazer is offline | |
| | #2 |
| and the Hat of Guessing Join Date: Nov 2007
Posts: 8,831
| What do you mean by "there aren't any structs"? Also: do you change maxIndex after you realloc? |
| tabstop is offline | |
| | #3 |
| Registered User Join Date: Jun 2008 Location: Northern Va
Posts: 18
| I have a looping statement to read through all of the array: Code: for(j=0;j<maxIndex;j++)
{
if(momentBin[j]==NULL)
break;
test =(momentBin[j])->val;
printf("%lf\n",test);
}
printf("Last J: %d",j);
|
| firetheGlazer is offline | |
| | #4 | |
| and the Hat of Guessing Join Date: Nov 2007
Posts: 8,831
| Quote:
| |
| tabstop is offline | |
| | #5 |
| Registered User Join Date: Jun 2008 Location: Northern Va
Posts: 18
| Wow, okay thanks for the catch. When I put in a continue, GDB spit out my assignment line with a segfault: Code: Program received signal SIGSEGV, Segmentation fault. 0x00401758 in main () at Z:\VortexStuff\Moment\moment.c:169 169 test =(momentBin[j])->val; |
| firetheGlazer is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Dynamic Array Resizing | dld333 | C++ Programming | 13 | 11-04-2005 12:13 AM |
| need help with dynamic array syntax | soldyne | C Programming | 3 | 10-11-2005 01:59 PM |
| Class Template Trouble | pliang | C++ Programming | 4 | 04-21-2005 04:15 AM |
| 2D dynamic array problem | scsullivan | C Programming | 3 | 12-30-2002 10:02 PM |
| Dynamic array allocation and reallocation | purple | C Programming | 13 | 08-01-2002 11:48 AM |