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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:35:55+00:00 2026-06-10T20:35:55+00:00

I am relatively new to C programming and I am trying to make a

  • 0

I am relatively new to C programming and I am trying to make a delimiter checker, but for some reason every time I run my code and it gets my input to check for delimiters, it has a segmentation fault (core dumped) error.

Below is the code of the main program:

int
main (void)
{
  char* mystring;
  printf ("Please enter a string\n");
  gets(mystring);
  if (fsm(mystring))
    {
      printf ("All matched");
    }
}

It seems like it never enters the subprogram fsm though, because I put in a printf right at the beginning of the subprogram and it never shows up. It does ask for my input though and prints it back out if I put the printf in the main program before the subprogram line.

Here is my prototype:

boolean fsm(char[]);

and here is the beginning of the subprogram if that is any help:

boolean fsm (char mystring[])
{
  printf("here\n");
  int counter = -1;
  int state = 0;
  c_stack top;
  c_init_stack (&top);
  while (1)
    {
      switch (state)
    {
    case 0:
      counter = counter + 1;
      if (is_open (*mystring))
        state = 1;
      else if (is_close (*mystring))
        state = 2;
      else if (mystring = '\0')
        state = 3;
      else
        state = 4;
      break;
  • 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-10T20:35:57+00:00Added an answer on June 10, 2026 at 8:35 pm

    You are trying to read into an uninitialized char*. Just declaring char *mystring doesn’t give you a string to work with: you’ll need to allocate space for the string.

    Either:

    char *mystring = malloc(MAX_STRING_LENGTH);
    

    Or:

    char mystring[MAX_STRING_LENGTH];
    

    Once you have a buffer, use fgets instead of gets. fgets allows you to specify an upper-bound on the number of characters read, so fgets along with something like MAX_STRING_LEN you’ll be able to accept only as much data as your buffer will hold.

    As it is, since C doesn’t initialize automatic (local) variables, mystring has an undefined value. It can point to any random part of memory. When you try to gets using this memory location, you’re trying to write to that memory that doesn’t belong to you.

    Finally, this condition with a single =: else if (mystring = '\0') is an assignment, and not an equality test.

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

Sidebar

Related Questions

Hi I'm relatively new to Android programming but I would be grateful of some
I am relatively new to Java and while trying out some code came across
I'm relatively new to programming. I'm trying to make a program at the moment,
I am relatively new to programming, and I am trying to learn to use
I'm relatively new to programming so excuse me if I get some terms wrong
I'm relatively new to graphics programming, and I've just been reading some books and
I am relatively new to socket programming. I am currently trying examples provided with
I'm relatively new to programming and trying get a (very) long list of information
Ok I am relatively new to Java Programming, but have previous experience in C++.
I am relatively new to C++ programming, but am a C programmer of 10

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.