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 8953037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:00:33+00:00 2026-06-15T14:00:33+00:00

I am using qsort function in c..its a in built function…it works well for

  • 0

I am using qsort function in c..its a in built function…it works well for strings having length less than 7..on strings whose length > 7, it gives “Segmentation fault (core dumped)”

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX 100

static int cmpr( const void *a, const void *b) { 
    return strcmp( *(char **)a, *(char **)b);
}


int main()
{
    int t;
    char str1[MAX],str2[MAX];

    scanf("%d",&t);

    while(t--)
    {
    scanf("%s %s",str1,str2);

    int len1=strlen(str1)/sizeof(char *);
    int len2=strlen(str2)/sizeof(char *);

    qsort(str1, len1, sizeof(char *), cmpr);
    qsort(str2, len2, sizeof(char *), cmpr);

    if((strstr(str1,str2)!=NULL)&& (strlen(str1)==strlen(str2)))
        printf("YES");
    else if((strstr(str2,str1)!=NULL) && (strlen(str1)==strlen(str2)))
        printf("YES");
    else if((strstr(str2,str1)!=NULL) && (strlen(str1)!=strlen(str2)))
        printf("NO");
    else if((strstr(str1,str2)!=NULL) && (strlen(str1)!=strlen(str2)))
        printf("NO");
    else
    printf("YES");
}



return 0;
}

…any idea why?

  • 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-15T14:00:35+00:00Added an answer on June 15, 2026 at 2:00 pm

    I think the lines

    int len1=strlen(str1)/sizeof(char *);
    int len2=strlen(str2)/sizeof(char *);
    

    should read

    int len1=strlen(str1);
    int len2=strlen(str2);
    

    Then the following should probably be changed

    qsort(str1, len1, sizeof(char), cmpr);
    qsort(str2, len2, sizeof(char), cmpr);
    

    As we do not have code for qsort I would hazard a guess that the cmpr function is also incorrect.

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

Sidebar

Related Questions

I am using the in-built function qsort() to sort a vector of class item
The below program sorts all the suffices of a string using qsort() library function.
I am using the C library function qsort to sort a bunch of integer
I am using the built in qsort to sort an array of structs. But
I really like the qsort function in C. It's so easy to use and
Lets take qsort()'s comparison callback function as an example int (*compar)(const void *, const
Ive got a task in C to sort a struct by using qsort struct
I need to sort an array of Strings in C. Here's how I'm using
I'm attempting to sort a struct of students in C. I'm using qsort and
Using NLTK and WordNet , how do I convert simple tense verb into its

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.