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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:22:10+00:00 2026-06-06T19:22:10+00:00

So I’m trying to do the practice exercises in K&R. It wants me to

  • 0

So I’m trying to do the practice exercises in K&R. It wants me to make a function similar to squeeze, I don’t get whats wrong with it. I desk checked it already. I don’t want a solution found on the net, I wanna understand why my code wont work.

//removes characters that are present in both strings
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define MAXLTR 15

void removesame(char s1[],char s2[]);

int main(void)
{
    char string1[MAXLTR],string2[MAXLTR];
    printf("Enter a string: ");
    scanf("\n%s",&string1);
    printf("\nEnter the letters/words to be removed: ");
    scanf("\n%s",&string2);
    removesame(string1,string2);
    printf("\nFinal output: %s",string1);
    getch();
}

void removesame(char s1[],char s2[])
{
    char temp[MAXLTR];
    int arraycntr,comparecntr;
    for(comparecntr = 0; comparecntr < MAXLTR; comparecntr++)
    {
        for(arraycntr = 0;arraycntr < MAXLTR;arraycntr++)
        {
            if(s1[arraycntr] == s2[arraycntr])
                s1[arraycntr] == '\t';
        }
    }
    comparecntr = 0;
    for(arraycntr = 0; arraycntr < MAXLTR; arraycntr++)
    {
        if(s1[arraycntr] != '\t')
        {
            temp[comparecntr] = s1[arraycntr];
            ++comparecntr;
        }
    }        
    for(arraycntr = 0; arraycntr < MAXLTR; arraycntr++)
        s1[arraycntr] = '\0';
    for(arraycntr = 0;arraycntr < MAXLTR; arraycntr++)
        s1[arraycntr] = temp[arraycntr];

}
  • 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-06T19:22:12+00:00Added an answer on June 6, 2026 at 7:22 pm

    This is not an assignment, but is an equality test:

    s1[arraycntr] == '\t'; 
    

    you meant:

    s1[arraycntr] = '\t';
    

    If you compile with a high warning level, the compiler may emit a message alerting you to this. The Microsoft VC compiler emits the following warning:

    C:\devel\cpp\stackoverflow\main.c(32) : warning C4553: ‘==’ : operator has no effect; did you intend ‘=’?

    The initial for loops only check if s1 and s2 have the same values in the same indexes, it does not check if a char in s1 exists anywhere in s2. The terminating conditions on the for loops should also be the lengths of s1 and s2, not MAXLTR:

    size_t arraycntr,comparecntr;
    for(comparecntr = 0; comparecntr < strlen(s2); comparecntr++)
    {
        for(arraycntr = 0;arraycntr < strlen(s1) ;arraycntr++)
        {
            if(s1[arraycntr] == s2[comparecntr])
                s1[arraycntr] = `\t`;
        }
    }
    

    The next for loop should use strlen(s1) also and just assign null terminator to temp after:

    comparecntr = 0;
    for(arraycntr = 0; arraycntr < strlen(s1); arraycntr++)
    {
        if(s1[arraycntr] != `\t`)
        {
            temp[comparecntr] = s1[arraycntr];
            ++comparecntr;
        }
    }
    temp[comparecntr] = '\0';
    

    temp is not initialised anywhere, so contains random data, apart from that just entered during this for. Without a null terminator in temp, s1 will end with no null terminator also (you will probably see garbage printed afterwards). Finally, just strlen(temp) + 1 when populating s1:

    for(arraycntr = 0;arraycntr < strlen(temp) + 1; arraycntr++)
        s1[arraycntr] = temp[arraycntr];
    

    The + 1 will copy the null terminator to s1.

    Minor note, instead of calling strlen() in the terminating condition of the for loops you can store this instead:

    size_t chars_to_copy;
    for(arraycntr = 0, chars_to_copy = strlen(temp) + 1;
        arraycntr < chars_to_copy;
        arraycntr++)
    {
        s1[arraycntr] = temp[arraycntr];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I am trying to render a haml file in a javascript response like so:
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.