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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:31:52+00:00 2026-06-12T21:31:52+00:00

I am making a C program. I have a function that everything seems to

  • 0

I am making a C program. I have a function that everything seems to be working great. But if I add another variable to it it suddenly does not work and I get a segmentation fault. (If I use gdb I get the error: Single stepping until exit from function __svfscanf_l,
which has no line number information. Program received signal: “EXC_BAD_ACCESS”.)

Here is my function:

void condition(char *command) {
printf("CAMMAND: %s\n", command);
char *cond;
char *expression;
char *file;
char *buffer;
buffer = malloc(200 * sizeof(char));

sscanf(command, "%s ( %s %s ) %[^\n]", cond, expression, file, buffer);

printf("COND: %s\n", cond);
printf("EX: %s\n", expression);
printf("File: %s\n", file);
printf("Command: %s\n", buffer);

if (!strcmp(expression, "checke")) {
    printf("CHECK EXISTS\n");
    if (file_exists(file)) {
        printf("EXISTS\n");
    }
} else if (!strcmp(expression, "checkd")) {
    printf("CHECK DIR\n");
} else if (!strcmp(expression, "checkr")) {
    printf("READ\n");
} else if (!strcmp(expression, "checkw")) {
    printf("CHECK WRITE\n");
} else if (!strcmp(expression, "checkx")) {
    printf("CHECK EX\n");
} else {
    printf("NOOOO\n");
}
}

However, if I even change it to something like below I get an error. It seems to be failing at the sscanf call. But that works when I don’t add some variable.

void condition(char *command) {
int flag;
printf("CAMMAND: %s\n", command);
char *cond;
char *expression;
char *file;
char *buffer;
buffer = malloc(200 * sizeof(char));

sscanf(command, "%s ( %s %s ) %[^\n]", cond, expression, file, buffer);

printf("COND: %s\n", cond);
printf("EX: %s\n", expression);
printf("File: %s\n", file);
printf("Command: %s\n", buffer);

if (!strcmp(expression, "checke")) {
    printf("CHECK EXISTS\n");
    if (file_exists(file)) {
        printf("EXISTS\n");
    }
} else if (!strcmp(expression, "checkd")) {
    printf("CHECK DIR\n");
} else if (!strcmp(expression, "checkr")) {
    printf("READ\n");
} else if (!strcmp(expression, "checkw")) {
    printf("CHECK WRITE\n");
} else if (!strcmp(expression, "checkx")) {
    printf("CHECK EX\n");
} else {
    printf("NOOOO\n");
}
}

Can’t seem to figure out why this is. Any help would be great!

  • 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-12T21:31:53+00:00Added an answer on June 12, 2026 at 9:31 pm

    You are getting memory corruption because you are passing pointers to characters, rather than pointers to character arrays, as the destination for %s conversions. expression, as defined, is uninitialized and points to some random memory location. Here is the relevant part of the sscanf documentation:

    s      Matches a  sequence  of  non-white-space  characters;  the  next
           pointer must be a pointer to character array that is long enough
           to hold the input sequence and the  terminating  null  character
    

    You need to allocate some space for expression etc.

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

Sidebar

Related Questions

Im making a program for class that manages a Hotel. I have a function
I am making a java program that uses the interpolation search below I have
I'm making a C++ program. In my program I have a function with an
I Have a java program that does sort of this: It starts off with
I'm making a program on the HUFFMAN ALGORITHM where I have one class of
I'm making a program where you're firing a 'blaster', and I have 5 ammo.
I am making a program like yelp. Some people have some accounts. So I
I have made a registration program. Making use of mysql database. Can I still
I making a program and wanted to make an update function... So lets say
I am making a program that automates the seperation of a csv file. We

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.