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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:00:01+00:00 2026-05-31T23:00:01+00:00

EDIT: solved it, turns out I should use %c not %s because foodSelect and

  • 0

EDIT: solved it, turns out I should use %c not %s because foodSelect and foodSize are characters not strings 😛 thanks

I’m trying to pass 3 values to the function output: foodChoice, foodSelect, foodSize (and foodOrderNum, and foodSubtotal but I haven’t gotten around to that yet).

However, when I try to printf foodSelect, I get a segmentation fault, but when I try to print foodChoice, I don’t. When I try to printf foodSize it just shows nothing.

source:

#include <stdio.h>
#include <string.h>

void question (char choice[]);
int output(char *foodChoice, char *foodSelect, char *foodSize);


void question (char choice[]) {

    char choiceYesNo;
    char *foodOptions;
    char *foodChoice;
    char *foodSelect;
    char *foodSize;
    int foodOrderNum = 0;
    float foodSubtotal = 0;

    switch (choice[0]) {
        case 'f':
            foodChoice = "Fish";
            foodOptions = "(K- Haddock, T- Halibut)";
            break;
        case 'c':
            foodChoice = "Chips";
            foodOptions = "(C- Cut, R- Ring)";
            break;
        case 'd':
            foodChoice = "Drinks";
            foodOptions = "(S- Softdrink, C- Coffee, T- Tea)";
            break;
    }

    printf("Do you order %s? (Y/N): ", foodChoice);
        scanf("%c", &choiceYesNo);
    printf("%s choice %s: ", foodChoice, foodOptions);
        scanf("%s", &foodSelect);
    printf("What size (L - Large, M - Medium, S - Small): ");
        scanf("%s", &foodSize);
    printf("How many orders do you want? (>=0): ");
        scanf("%d", &foodOrderNum);
    output(foodChoice, foodSelect, foodSize);
}

int output(char *foodChoice, char *foodSelect, char *foodSize) {

    // printf("You ordered %s: %s - SIZE: %s   amount ordered: , subtotal price: \n", 
    // foodChoice, foodSelect, foodSize);

    printf("\n\n%s\n", foodSelect);
    // printf("\n\n%s\n", foodSelect);

}

int main() {

    question("chips");


}
  • 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-31T23:00:02+00:00Added an answer on May 31, 2026 at 11:00 pm

    You haven’t allocated memory for:

    char *foodOptions;
    char *foodChoice;
    char *foodSelect;
    char *foodSize;

    Do malloc and allocate memory. Note that:

    char *foodChoice="Fish";
    

    And

    char *foodChoice;
    foodChoice="Fish";
    

    are not the same.

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

Sidebar

Related Questions

UPDATE: Solved. Thanks BusyMark! EDIT: This is revised based on the answer below from
SOLVED: As it turns out, my problem was rooted in the fact that I
Edit : Solved, there was a trigger with a loop on the table (read
Edit: Solved. Hi, I'm starting with Qt, I try to connect a slot to
edit #2: Question solved halfways. Look below As a follow-up question, does anyone know
Edit: I have solved this by myself. See my answer below I have set
EDIT: This problem has been solved. See below. Hey all. I'm building an iPhone
edit: I was trying to solve a spoj problem. Here is the link to
SOLVED see Edit 2 Hello, I've been writing a Perl program to handle automatic
after a hard work, my brain turns out of service.. (it is 11:40 P.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.