Thread: threads...

  1. #1
    Registered User newbie_grg's Avatar
    Join Date
    Jul 2002
    Posts
    77

    Angry threads...

    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");
    }
    "If knowledge can create problems, it is not through ignorance that we can solve them. "
    -Isaac Asimov(1920-1992)

  2. #2
    Registered User newbie_grg's Avatar
    Join Date
    Jul 2002
    Posts
    77

    hey sorry...

    well i placed ssort in place of qsort but it shows the same error message.
    Salem do you have any suggestions now??
    "If knowledge can create problems, it is not through ignorance that we can solve them. "
    -Isaac Asimov(1920-1992)

  3. #3
    Registered User newbie_grg's Avatar
    Join Date
    Jul 2002
    Posts
    77

    ok...

    i am such a dumbo!!! ...i got your point .. i have 4 but i sorted 6. Thnax for the thing you said but seriously speaking i think the error regarding threads is related to memory.
    "If knowledge can create problems, it is not through ignorance that we can solve them. "
    -Isaac Asimov(1920-1992)

  4. #4
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    first of all, in MSVC++, the error that occurs is an access violation, which means you're trying to write to memory that isn't yours. second, you didn't return a value from main(). but thats alright really.

    salem is right, you are specifying too many objects, so qsort tries to write to memory that you have not allocated. just a simple error.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 10-17-2008, 11:28 AM
  2. Yet another n00b in pthreads ...
    By dimis in forum C++ Programming
    Replies: 14
    Last Post: 04-07-2008, 12:43 AM
  3. Classes and Threads
    By Halloko in forum Windows Programming
    Replies: 9
    Last Post: 10-23-2005, 05:27 AM
  4. problem with win32 threads
    By pdmarshall in forum C++ Programming
    Replies: 6
    Last Post: 07-29-2004, 02:39 PM
  5. Block and wake up certain threads
    By Spark in forum C Programming
    Replies: 9
    Last Post: 06-01-2002, 03:39 AM