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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:47:06+00:00 2026-05-15T23:47:06+00:00

here is code which prints longest string duplicated M times #include <iostream> #include <stdlib.h>

  • 0

here is code which prints longest string duplicated M times

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

using namespace std;
#define M 1
#define  MAXN  5000000
char c[MAXN],*a[MAXN];
int pstrcmp( char **p,char **q){  return strcmp(*p,*q) ;}
int comlen(char *p,char *q){

    int i=0;
     while  (*p &&(*p++==*q++)){
         i++;
     }


      return i;


}
int main(){

    int maxlen=-1;
     int maxi; 
      int ch,n=0; 
       while ((ch=getchar())!=EOF){
           a[n]=&c[n];
            c[n++]=ch;
       }
       c[n]=0;
       qsort(a,n,sizeof( char *),pstrcmp);
         for (int i=0;i<n-M;i++) 
               if (comlen(a[i],a[i+M])>maxlen){
                    maxlen=comlen(a[i],a[i+M]);
                    maxi=i;
               }
               printf("%.*s\n",maxlen,a[maxi]);



     return 0;
}

but here is mistake

1>c:\users\david\documents\visual studio 2010\projects\longest_repeted\longest_repeated.cpp(33): error C2664: 'qsort' : cannot convert parameter 4 from 'int (__cdecl *)(char **,char **)' to 'int (__cdecl *)(const void *,const void *)'
1>          None of the functions with this name in scope match the target type
  • 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-15T23:47:06+00:00Added an answer on May 15, 2026 at 11:47 pm

    Change

    int pstrcmp( char **p,char **q){  return strcmp(*p,*q) ;}
    

    to

    int pstrcmp(const void *p, const void *q)
    {  
      return strcmp(*reinterpret_cast<const char**>(p), *reinterpret_cast<const char**>(q));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my code which checks if the file exists : #include<stdio.h> #include<zlib.h> #include<unistd.h>
Here is some code I wrote (using GCC's __restrict__ extension to C++): #include <iostream>
i have program which prints all char from char_min to char_max here is code
Here's a bit of code which prints out the squares of the numbers from
Here is a code sample of PHP function which prints HTML links. For some
Here is the code which test in IE8: var stack = []; function test()
Here is jquery code which hides my table cells with the ID of .style2:
Here is my code which is doing the conversion from hex to decimal. The
I have some code here which works perfectly in firefox but not in chrome
I have this piece of Open MP code here which performs an integeration of

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.