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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:20:10+00:00 2026-06-12T19:20:10+00:00

I am currently writing a program’s main function(the bare-bone function so far) so far

  • 0

I am currently writing a program’s main function(the bare-bone function so far) so far I’ve only included the “end” command to end the program. Whenever anything else is typed that isn’t a command, it will output an error message. However, now that I’m inputting more commands within the loop, it doesn’t seem to be recognizing anything else. I’m writing a program that creates polynomials after prompting the user to enter coefficients and exponents.

The command is adc(add coefficient command) and after a space you’re supposed to add an integer standing for the coefficient and another space with another integer standing for the exponent.

Example: adc 4 5
Output: 4x^5

int main(void){
    char buf[5]; //Creates string array
    unsigned int choice;
    printf("Command? "); // Prompts user for command
    fflush(stdout);
    gets(buf); //Scans the input

    while(strncmp(buf, "end", 3) != 0) //Loop that goes through each case, so long as the command isn't "end".
    {
        switch( choice ){
        //Where the other cases will inevitably go
            if((strcmp(buf,"adc %d %d"))== 0){
            }
        break;
            default:
              printf("I'm sorry, but that's not a command.\n"); //Prints error message if input is not recognized command
    fflush(stdout);
              break;
        }
        printf("Command? "); //Recycles user prompt
        fflush(stdout);
        gets(buf);
    }
    puts("End of Program."); //Message displayed when program ends
}
  • 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-12T19:20:11+00:00Added an answer on June 12, 2026 at 7:20 pm

    You can’t use a format string like this: strcmp(buf,"adc %d %d") to test for a certain kind of input. Your strcmp will only signal string equality if the use inputs literally: "adc %d %d", not adc followed by two integers.

    You’ll need to parse the input string manually, by tokenizing around whitespace characters, checking the first token with strcmp against e.g. adc, then parsing the numbers separately.

    I don’t notice any case statements in your switch. It looks like you can just remove the switch, since you’re not using choice anywhere.

    Also, don’t use gets, use fgets instead.

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

Sidebar

Related Questions

I'm currently writing a lightweight program that consolidates many command line and other external
I am currently writing a program using Weka that builds a model (using one
I'm currently writing a program in Python, and I would like to determine the
I'm currently writing a java program that requires some Data to run. The data
I'm currently writing myself a little C# back up program. I'm using a standard
I am writing a program that generates excel reports, currently using the Microsoft.Interop.Excel reference.
I am writing a Python program which runs a virtual terminal. Currently I am
I'm currently writing a function what would create a zip file, which will be
I'm currently writing a program that needs to compare each file in an ArrayList
Backgorund I am currently writing a program that allows a user to select 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.