Variable is not a structure and Sort char **

This is a discussion on Variable is not a structure and Sort char ** within the C Programming forums, part of the General Programming Boards category; Alright, two questions here. First off I have a dictionary.h file and a HashDictionary.h and BinSearchDictionary.h each of which inherits ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    11

    Sorting char **

    Alright, two questions here. First off I have a dictionary.h file and a HashDictionary.h and BinSearchDictionary.h each of which inherits from dictionary. What I want to do is have a variable dict which is either a HashDictionary object or a BinSearchDictionary object depending on the argument passed to the command line. What AI have right now is this:

    Dictionary * dict;
    if (hash)
    dict=new HashDictionary();
    else
    dict=new BinSearchDictionary();

    When I try to compile I get an error: Variable dict is not a structure. Any ideas on how to fix this?

    Second Question
    I am trying to sort an array of strings(char **) using qsort. I copy the strings into the array using strncpy and they copy fine. When I sort I get a weird output. Below is the code and the elements of the string after sorting.

    // stringArray is passed into the function as char * stringArray[],
    //and contains{"Apple","Hello","World","Here","I","Am",N ULL}
    char ** pa=(char **)stringArray;
    int x=0;
    while (pa[x]!=NULL)
    {
    strncpy((char *)(_dictionary+numElems),pa[x],2048);
    x++;
    numElems++;
    }
    qsort((void *)_dictionary,numElems,sizeof(char *),comp);
    return 1;


    And the Contents of _dicitonary after qsort:

    Am
    ApplHellHereI
    HellHereI
    HereI
    I
    Worl

    Does anyone know what the problem is here? Thanks for the help in advance.
    Last edited by ChazWest; 03-08-2002 at 12:16 PM.

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    11
    Ok, figured out the first problem, still baffled by the second though.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 11:43 AM
  2. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  3. linked lists, strcmp(), char array, & a structure
    By xddxogm3 in forum C++ Programming
    Replies: 5
    Last Post: 10-04-2003, 07:24 PM
  4. how do I sort this structure???
    By jgonzales in forum C Programming
    Replies: 14
    Last Post: 08-21-2002, 10:00 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 02:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21