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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:12:43+00:00 2026-05-23T13:12:43+00:00

Why am I getting a bus error? The problematic line is marked inside the

  • 0

Why am I getting a bus error? The problematic line is marked inside the code.

Exercise 2-4.
Write an alternative version of squeeze(s1,s2) that deletes each character in s1 that matches any character in the string s2.

    #include <stdio.h>

    /*
     * Detects if a char is inside a string
     */
    char in_string(char c, char s[]) {
        int i = 0;
        while (s[i] != '\0') {
            if (s[i++] == c)
                return 1;
        }
        return 0;
    }

    /*
     * Returns the string s without any chars that are in map
     */
    void squeeze(char s[], char map[]) {
        int i, j;

        for (i = j = 0; s[i] != '\0'; i++) {
            if (! in_string(s[i], map)) {
                s[j++] = s[i]; // <--- Bus Error
            }
        }
        s[j] = '\0';

        printf("%s\n", s);
    }

    main() {
        squeeze("XALOMR", "AO");
        squeeze("EWRTOG", "RGV");
    }
  • 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-23T13:12:44+00:00Added an answer on May 23, 2026 at 1:12 pm

    Because "XALOMR" is a string literal (which is read-only) and you cannot modify it (as you do here: s[j++] = s[i];)

    A way around it is:

    main() {
        char s1[] = "XALOMR";
        char s2[] = "EWRTOG";
    
        squeeze(s1, "AO");
        squeeze(s2, "RGV");
    }
    

    Which will create an array of chars on the stack.

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

Sidebar

Related Questions

I am getting a "Bus error" when I try to run this code compiled
I am getting Bus Error trying to read stdin into a char* variable. I
Getting the above error in following code. How to rectify it. Thanks. Please look
I would like to understand why I am getting a bus error with this
i am getting weird python bus error when building a web app. http://pastie.org/714569 i
Getting an error with my code found HERE ... Which is a culmination of
I am trying to write a parser that parses out HTML times for bus
Getting this error: 2009-09-03 12:44:02.307 xcodebuild[307:10b] warning: compiler 'com.apple.compilers.llvm.clang.1_0.analyzer' is based on missing compiler
Getting a rendering error for this form: 'NoneType' object has no attribute 'widget' http://dpaste.com/88585/
Getting a 'marshal data too short' error when trying to install the mysql gem

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.