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

The Archive Base Latest Questions

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

I wrote the following function for removing duplicate characters from a string..For ex: if

  • 0

I wrote the following function for removing duplicate characters from a string..For ex: if
str = “heeello;
removeDuplicate(str)

will return helo…But it shows some error on runtime .I have added some printf() statements for debugging…Can anyone tell me what the problem is ?

char* removeDuplicate(char str[])//remove duplicate characters from a string,so that each character in                a string is not repeating  
{
    int i = 0,j;
    char ch;
    printf("\nstr is %s",str);
    while((ch = str[i++] )!= '\0')
    {
    j = i;
    printf("\n----ch = %c----",ch);
    while(str[j] != '\0')
    {
        printf("\n--------Checking whether %c =  %c \n",str[j],ch);
        if(ch == str[j])
        {
            printf("\n------------Yes");
            while(str[j]!='\0')
            { 
                printf("\nRemoving %c %d -- \n",str[j]);
                str[j] = str[++j];
                --i;

            }

            break;
        }
        printf("\n------------No");

       //printf("\njj");
        j++;
    }
}

return str;
}
  • 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-31T03:11:55+00:00Added an answer on May 31, 2026 at 3:11 am

    You are passing a string literal, which you are not allowed to modify to this function, instead you should do:

    char myStr[] = "heee";
    removeDuplicate(myStr);
    

    Also, please note that in the following lines your have to specifiers inside the printf (%c %d), but you pass only one argument (str[j]):

    printf("\nRemoving %c %d -- \n",str[j]);
    

    This may cause all sorts of bad things…

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

Sidebar

Related Questions

I wrote following code...but i am getting Error like: Error 1 'LoginDLL.Class1.Login(string, string, string)':
I wrote the following function to convert a time in milliseconds to a string
I wrote the following simple function that takes two parameters mostly coming from another
(VB.NET, .NET 3.5) I wrote the following function to read some text from txt
I wrote the following function to view data in a grid from F# interactive:
I wrote the following function in haskell, as it will enumerate every integer: integers
I just wrote the following function: public string Ebnf { get { var props
I just wrote the following C++ function to programmatically determine how much RAM a
I wrote a managed C++ class that has the following function: void EndPointsMappingWrapper::GetLastError(char* strErrorMessage)
I wrote the following: Object.prototype.length = function(){ var count = -1; for(var i in

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.