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

  • SEARCH
  • Home
  • 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 827823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:37:54+00:00 2026-05-15T03:37:54+00:00

Ive got a task in C to sort a struct by using qsort struct

  • 0

Ive got a task in C to sort a struct by using qsort

struct user {
    enum SEX{m, f} sex;
    char name[32];
    char phonenr[32];

};
typedef struct user User;

the users will be stored in a array of 25 elements

but how do i sort them on something like name ?

  • 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-05-15T03:37:55+00:00Added an answer on May 15, 2026 at 3:37 am

    In this case it’s pretty easy, since strcmp works nicely with qsort. Try:

    int compareUser(const void *v1, const void *v2)
    {
        const User *u1 = v1;
        const User *u2 = v2;
        return strcmp(u1->name, u2->name);
    }
    

    Then use it like this:

    qsort(array, 25, sizeof(User), compareUser);
    

    Good luck!

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

Sidebar

Related Questions

Ive got task to create application which can post data on users friends walls.
I've got an Ant task (using the maven task) set up to automatically download
I've got an installation task using InnoSetup which I'm not quite sure how to
I've got an ant jar task: <target name=jar> <jar destfile=${generated.jars.dir}/hello-${environment}.jar> <fileset dir=${generated.classes.dir}/> <fileset dir=${environment.dir}/${environment}
Yesterday I've got a task to implement a validation on the field where user
Ive got task to write code to export html table with headers to excel.
Ive got a strange task. Specifically i want to check for insane media file
I've got this ant task working(sending email) on my machine : <project name=send_mail_test default=send_mail_test>
I've got a Model Task with a member due_date. I'm using Chronic to take
I've got an activity that keeps reading words to the user, and using onUtteranceCompleted

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.