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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:40:40+00:00 2026-05-20T18:40:40+00:00

DISCLOSURE: This is homework. The code below is meant to read a command file

  • 0

DISCLOSURE: This is homework.

The code below is meant to read a command file formatted like:

ADD 6 6 5
ADDTERM 0 1 1
MULTIPLY 2 40

and call the appropriate command using the given parameters. For some reason, while ADD and ADDTERM work as expected, I get a segfault when the multiply line is read.

    int arg_1 = 0, arg_2 = 0, arg_3 = 0;

    while(fscanf(commands, "%s", command) != EOF)
    {
            if(strcmp(command, "ADDTERM") == 0)
            {
                    /*The following line runs fine!*/
                    fscanf(commands, "%d %d %d",
                                    &arg_1, &arg_2, &arg_3);
                    printf("ADDTERM, Poly: %d, Coeff: %d, Exp: %d\n",
                                    arg_1, arg_2, arg_3);
                    if(polys[arg_1] == NULL)
                    {polys[arg_1] = CreatePolynomial();}
                    AddTermToPoly(polys[arg_1], arg_2, arg_3);
            }

            else if(strcmp(command, "MULTIPLY") == 0)
            {
                    /*The following line results in a segfault*/
                    fscanf(commands, "%d %d", &arg_1, &arg_2);

                    printf("MULTIPLY, Poly: %d, Multiplier: %d\n",
                                    arg_1, arg_2);
                    MultiplyPoly(polys[arg_1], arg_2);
            }

            /*...*/  
   }

This is also only a problem on my school’s Linux server. My home computer runs it just fine, using “gcc version 4.4.5 (Ubuntu/Linaro 4.4.4-14ubuntu5)”, whereas my school uses “gcc version 4.1.2 20080704 (Red Hat 4.1.2-48)”

Any ideas why this would be? Your help is appreciated!

  • 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-20T18:40:41+00:00Added an answer on May 20, 2026 at 6:40 pm

    You need to leave room for a null terminus ‘\0’ in your string. You were okay with ADDTERM because it has 1 less letter than MULTIPLY.

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

Sidebar

Related Questions

Full disclosure : This is for a homework assignment. This is driving me nuts.
Full disclosure, this is part of a homework assignment (though a small snippet, the
full disclosure - this is for a homework assignment. And I normally would not
I have this old jquery script for progressive disclosure: (notice the $(this).text('more...') code changes
How would you define testing? In the interest of full disclosure, I'm posting this
I would like to use a custom version of the standard disclosure accessory image
First, in order to provide full disclosure, I want to point out that this
First off, full disclosure: This is going towards a uni assignment, so I don't
It seems that with an object like this: #<Course id: 1, name: Targeting Triple
I'm trying to write a method that will operate like this: NSString *responseData =

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.