#include 
// Array of string pointers to be sorted.
static const char* brothers[] =
{
    "Frederick William",
    "Joseph Jensen",
    "Harry Alan",
    "Walter Ellsworth",
    "Julian Paul"
};
// Linkage specification.
extern "C"
{
    // Prototype of C function.
    void SortCharArray(const char**);
    // C++ function to be called from the C program
    int SizeArray()
    {
        return sizeof brothers / sizeof (char*);
    }
}
////////////////////////////////////////
// The main() function.
////////////////////////////////////////
int main()
{
    // Sort the pointers.
    SortCharArray(brothers);
    // Display the brothers in sorted order.
    int size = SizeArray();
    for (int i = 0; i < size; i++)
        std::cout << brothers[i] << std::endl;
    return 0;
}

Like it on Facebook, Tweet it or share this article on other bookmarking websites.

No comments