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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:29:19+00:00 2026-06-11T10:29:19+00:00

As the title indicates, this should be very easy. I don’t understand why, but

  • 0

As the title indicates, this should be very easy. I don’t understand why, but I’m getting a Bus error: 10 when I run this.

This should be so easy! But I can’t seem to solve it…. ugh. Please help.

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

main() {

char *string[20];
char buffer[256];

int wordCount = 0;

    while ((scanf("%s", buffer) != EOF)) {
        printf("%s%d\n", buffer, wordCount);
        string[wordCount++] = (char *) malloc (strlen(buffer)+1); 
        strcpy (string[wordCount], buffer);
    }

int j;

printf("There are %d words.\n", wordCount+1);

for (j = 0; j < wordCount; j++)
{

    printf("%s\n", string[j]);
}   
}
  • 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-11T10:29:20+00:00Added an answer on June 11, 2026 at 10:29 am
    string[wordCount++] = (char *) malloc (strlen(buffer)+1); 
    strcpy (string[wordCount], buffer);
    

    You’re allocating to string[wordCount] and then you’re incrementing wordCount. Then you proceed to strcpy to this new, unallocated element, which is illegal.

    Increment wordCount after strcpy instead.

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

Sidebar

Related Questions

This should be very straight forward, but even looking at the other questions, I
This is hopefully a very simple question, but one a lot of Googling has
This question might appear very simple, but i haven't found an answer yet, so
As the title indicates, I would like to do the following, but the compiler
I can't think of a good title, but my question is not as naive
As the title indicates I am looking for the solution to this with the
As the title indicates, are there any C/C++ bytecode compilers/interpreters? I'm writing an application
As the title indicates, the root view is my navigation controller, and it is
As the title indicates I'm populating an Infopath textbox control using a SharePoint list
As the title indicate, how should I name the variables that reference GUI elements.

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.