Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8745697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:04:32+00:00 2026-06-13T12:04:32+00:00

here is C code from the book The C programming language: #include <stdio.h> #include

  • 0

here is C code from the book “The C programming language”:

#include <stdio.h>
#include <string.h> 

#define MAXLINES 5000    /* max #lines to be sorted */
char *lineptr[MAXLINES]; /* pointers to text lines */

int readlines(char *lineptr[], int nlines);
void writelines(char *lineptr[], int nlines);

void qsort(void *lineptr[], int left, int right, 
        int (*comp)(void *, void *));

int numcmp(char *, char *);

/* sort input lines */
main(int argc, char *argv[])
{
    int nlines;

    int numeric = 0; /* number of input lines read */

    if (argc > 1 && strcmp(argv[1], "-n") == 0)  /* 1 if numeric sort */
        numeric = 1;
    if ((nlines = readlines(lineptr, MAXLINES)) >= 0) {
        qsort((void**) lineptr, 0, nlines-1, // MY QUESTION: WHY lineptr IS CAST TO POINTER TO A VOID POINTER
                (int (*)(void*,void*))(numeric ? numcmp : strcmp));
        writelines(lineptr, nlines);
        return 0;
    } else {
        printf("input too big to sort\n");
        return 1;
    }
}


void qsort(void *v[], int left, int right,
        int (*comp)(void *, void *))
{
    int i, last;
    void swap(void *v[], int, int);
    // rest of code
}

Why when qsort function is called first argument is being cast to pointer to a void pointer (void **) and not just to pointer to void (void *) . Please tell me why is it so?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:04:33+00:00Added an answer on June 13, 2026 at 12:04 pm

    Compilers will warn you these days unless you cast non-void pointers to void pointers when you pass them as void pointers (if that made any sense). I think you knew that, though.

    The signature of void **lineptr is equivalent in C to void *lineptr[], which is the type of pointer that qsort takes as an argument. See this site for more details.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following sample code is from Joe Armstrong's Programming Erlang book: max(N) -> Max
I am new to obj-c programming, I read Kochan's book. here is code from
I'm trying out several exercises from a Java programming book. I have the code
From the book Programming Languages: Application and Interpretation page 6 I try to code
Here is code from MSDN . I don't understand why the work isn't just
Given the code from here : class lazy_init { mutable std::once_flag flag; mutable std::unique_ptr<expensive_data>
I am using the Bunch code from here: How to use dicts in Mako
I've copied all the code from here but instead of looking like the sample
I'm using some code from here to determine when determining when the last finger
I found this code from here: http://www.cssportal.com/form-elements/text-box.htm But the problem is you can still

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.