hey guys i need some help here.. when i run any program involving pointers , i get error called thread stopped at some hex values and a box pops out containind i guess memory addresses. anyway if you guys could help me out , heres the sample program from "the c++ programming language" , bjarne stroustrup which i run in borland compiler and got the error mentioned above.
Code:
#include <iostream>
#include <stdlib.h>
struct user
{
char* name ;
char* id ;
int dept ;
};
user heads[]= {
"ritchie d.m" , "dmr", 11271 ,
"sethi R." , "ravi" , 11272 ,
"szymanski" , "tgs" , 11273 ,
"kernighan B.W." ,"bwk" , 11276
};
void print_id(user* v , int n)
{
for( int i=0; i<n ; i++ )
{ cout<<v[i].name <<"\t"<< v[i].id <<"\t" <<v[i].dept << "\n";
}
}
int cmp1(const void* p , const void* q)
{
return strcmp(static_cast<const user*>(p)->name , static_cast<const user*>(q)->name);
}
int cmp2(const void* p , const void* q)
{
return static_cast<const user*>(p)->dept - static_cast<const user*>(q)->dept;
}
int main(void)
{
cout <<" heads in alphabetical order :\n";
qsort( heads,6,sizeof(user), cmp1);
print_id(heads, 6);
cout << '\n';
cout <<" heads in order of department number:\n";
qsort(heads , 6, sizeof(user) , cmp2);
print_id(heads , 6);
system("pause");
}