?
=?iso-8859-1?B?cG92b2Hn428=?=
Hi all,
I need some help because I don't know what happens here.
At the code above at the lines
printf("before free");
free(people);
printf("after free");
At the free line I got error
"*** glibc detected *** double free or corruption (out): 0x0804a008 ***
before freeAborted"
I'm using gcc 4.0.3, ubuntu and I want to keep the use of pointer in
the program.
If possible I need some how-to debug using gcc and linux.
thanks
#include <stdio.h>
#include <stdlib.h>
struct person
{
char name[20];
float value;
}*people, *p;
sort(int size)
{
int cont=0;
struct person temp[size];
for(cont=0;cont<=size;cont++)
{
if(people[cont].value<people[cont+1].value)
temp[cont]=p[cont];
people[cont]=people[cont+1];
people[cont+1]=temp[cont];
}
}
int main(void)
{
int a=0,size=0;
do
{
scanf("%d",&size);
people=malloc((size+1) * sizeof(struct person));
p=people;
for(a=0;a<size;a++)
{
scanf("%s",&p->name);
scanf("%f",&p->value);
p++;
}
sort(size);
p=people;
for(a=0;a<size;a++)
{
printf("%s\n",p->name);
printf("%g\n",p->value);
p++;
}
printf("before free");
free(people);
printf("after free");
}while(size>0);
}
I need some help because I don't know what happens here.
At the code above at the lines
printf("before free");
free(people);
printf("after free");
At the free line I got error
"*** glibc detected *** double free or corruption (out): 0x0804a008 ***
before freeAborted"
I'm using gcc 4.0.3, ubuntu and I want to keep the use of pointer in
the program.
If possible I need some how-to debug using gcc and linux.
thanks
#include <stdio.h>
#include <stdlib.h>
struct person
{
char name[20];
float value;
}*people, *p;
sort(int size)
{
int cont=0;
struct person temp[size];
for(cont=0;cont<=size;cont++)
{
if(people[cont].value<people[cont+1].value)
temp[cont]=p[cont];
people[cont]=people[cont+1];
people[cont+1]=temp[cont];
}
}
int main(void)
{
int a=0,size=0;
do
{
scanf("%d",&size);
people=malloc((size+1) * sizeof(struct person));
p=people;
for(a=0;a<size;a++)
{
scanf("%s",&p->name);
scanf("%f",&p->value);
p++;
}
sort(size);
p=people;
for(a=0;a<size;a++)
{
printf("%s\n",p->name);
printf("%g\n",p->value);
p++;
}
printf("before free");
free(people);
printf("after free");
}while(size>0);
}