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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:26:28+00:00 2026-06-04T23:26:28+00:00

Very new to C so please bear with me! I’m trying to read 3

  • 0

Very new to C so please bear with me! I’m trying to read 3 arguments separated by spaces from “instruction” into the 3 strings using sscanf. I’ve got the following code so far:

char * buffer;
buffer = (char*) malloc (5000);
sscanf(instruction, "%s %s %s", &opcode, &arg1, &arg2, buffer);

However whilst it compiles fine, there is a seg fault on the last line where the sscanf is. Last time I saw this error it was because there wasn’t enough memory in the variables to store the information. I’m guessing I’m not using malloc properly?

I can’t post the entire code unfortunately as it doesn’t belong to me.

  • 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-04T23:26:32+00:00Added an answer on June 4, 2026 at 11:26 pm

    You are using sscanf improperly. Try this:

    #define BUFFER_SIZE 1024 /* generally good practice to use constants */
    
    char *opcode = (char *)malloc(BUFFER_SIZE);
    char *arg1 = (char *)malloc(BUFFER_SIZE);
    char *arg2 = (char *)malloc(BUFFER_SIZE);
    sscanf(instruction, "%s %s %s", opcode, arg1, arg2);
    

    Depending on how you use these variables, it might be better to allocate them on the stack:

    char opcode[BUFFER_SIZE];
    char arg1[BUFFER_SIZE];
    char arg2[BUFFER_SIZE];
    sscanf(instruction, "%s %s %s", opcode, arg1, arg2);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, I'm very new to Java so please bear with me. I am using
I am very new to using preg_replace and such so please bear with me.
I'm coming from C# and very new at this so please bear with me.
I am very new to Perl, so please bear with my simple question: Here
I'm very new to iPhone development so please bear with me. I'm following the
I'm very new to working with lift, so please bear with me. If I
I am new to this, so please bear with me... I need to very
Im very new to javascript and jquery so please bear with me. Here's my
I'm very new to Ruby, so please bear with me. Why is it a
I am very very new to OpenGL, so please bear with me. :) I'm

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.