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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:58:31+00:00 2026-06-14T12:58:31+00:00

noob question here: I’m trying to write a simple menu interface, but I keep

  • 0

noob question here:
I’m trying to write a simple menu interface, but I keep getting a segmentation fault error and I can’t figure out why.

#include <stdlib.h>
#include <stdio.h>
int flush(); int add(char *name, char *password, char *type); int delete(char *name);
int edit(char *name, char *password, char *type, char *newName, char *newPassword, char            *newType);
int verify(char *name, char *password);



int menu(){
    int input;
    char *name, *password, *type, *newName, *newPassword, *newType;
    printf("MAIN MENU \n ============\n");
    printf("1. ADD\n");
    printf("2. DELETE\n");
    printf("3. EDIT\n");
    printf("4. VERIFY\n");
    printf("5. Exit\n");
    printf("Selection:");
    scanf("%d", &input);
    flush();
    switch (input){

    case 1:
        printf("%s\n", "Enter Name:");
        scanf("%s", name);
        flush();
        printf("%s\n", "enter password" );
        scanf("%s", password);
        flush();
        printf("%s\n","enter type" );
        scanf("%s",type);
        add(name, password, type);
        menu();
        break;
    case 2:
        printf("Enter Name:" );
        scanf("%s",name);
        flush();
        delete(name);
        menu();
        break;
    case 3:
        printf("Enter Name:\n");
        scanf("%s",name);
        flush();
        printf("Enter Password\n");
        scanf("%s", password);
        flush();            
        printf("enter type:\n");
        scanf("%s", type);
        flush();
        printf("enter your new username:\n");
        scanf("%s",newName);
        flush();
        printf("enter your new password\n");
        scanf("%s", newPassword);
        flush();
        printf("enter your new type\n");
        scanf("%s",newType);
        flush();
        edit(name, password, type, newName, newPassword, newType);
        menu();
        break;
    case 4:
        printf("Enter Name\n");
        scanf("%s",name);
        flush();
        printf("Enter Password\n");
        scanf("%s",password);
        flush();
        verify(name, password);
        menu();
        break;
    case 5:
        return 0;
    default:
        printf("invalid input, please select from the following:\n");
        menu();
}
    return 0;
    }

    int flush(){
     int ch;
     while ((ch = getchar()) != EOF && ch != '\n') ;
     return 0;
    }

I get the segmentation fault after entering two fields, in any menu option

  • 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-14T12:58:32+00:00Added an answer on June 14, 2026 at 12:58 pm

    You need to initialize your pointers. Alternatively, use stack-allocated arrays.

    For example, instead of char *name, do char name[20]. (Note that this will limit your input to 19 characters; use a larger buffer if necessary.)

    Right now, you are passing uninitialized pointers into scanf() which effectively means that scanf() is going to write to an undefined area of memory. It might work on one execution and then fail on the next. It might corrupt memory elsewhere in the process’ address space.

    Don’t use uninitialized variables, and consider turning up your compiler warnings as high as they will go; the compiler can catch errors like this and emit a warning.

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

Sidebar

Related Questions

Noob dumb question, no doubt -- but here it is: Trying to tutorialize myself
Noob question here, but I am teaching myself C and trying to figure out
Total noob question, but here. CSS .product__specfield_8_arrow { /*background-image:url(../../upload/orng_bg_arrow.png); background-repeat:no-repeat;*/ background-color:#fc0; width:50px !important; height:33px
i think this is a bit of a noob question, but here goes. I
complete noob to Haskell here with probably an even noobier question. I'm trying to
Total noob question here, but not finding the answer via search. What is the
I have a noob question here. I'm getting my head around the C++ structure
Ok, please bear with my noob question here. I'm doing the simple task of
This is probably a noob question that I will get slated for but here
A noob question here, by a novice programmer. I am trying to do a

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.