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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:24:56+00:00 2026-06-12T03:24:56+00:00

#include <stdio.h> #include <math.h> #include <stdlib.h> int main(void) { char wunit[2]; // weight unit

  • 0
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main(void)
{
    char wunit[2]; // weight unit
    char hunit[2]; // height unit

    double weight, height;

    printf("Enter the body weight: ");
    scanf("%lf%s", &weight, &wunit); // input weight and unit eg. 150lb

    printf("Enter the height: "); 
    scanf("%lf%s", &height, &hunit); // input height and unit eg. 5.65 ft

    printf("The height unit: %s\n", hunit);
    printf("The weight unit: %s", wunit);

    return 0;
}

This code only prints out the height unit, and not the weight unit. What can I do to fix it?

  • 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-12T03:24:58+00:00Added an answer on June 12, 2026 at 3:24 am

    You aren’t allowing much space for those two strings: only 2 char for each. Note that C strings also require space for a null-terminating character to mark the end of the string.

    With the null-terminating character, your two strings can each only properly hold a single character. When you input e.g. “lb” and “ft”, you’re using data outside the bounds of your arrays. Change the size of your arrays to (at least) 3, and see if the code prints out both units correctly:

    char wunit[3]; // weight unit
    char hunit[3]; // height unit
    

    Your code works fine for me with larger arrays.

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

Sidebar

Related Questions

#include<stdio.h> #include<math.h> int main(int argc, char **argv){ // read in the command-line argument double
#include <stdio.h> void wrapperPrint(char* s) { printf(s); return; } int main() { wrapperPrint(Hello world\n);
#include<stdio.h> #include<stdlib.h> char* re() { char *p = hello; return p; } int main()
#include <stdio.h> #include <stdlib.h> int main(void) { int x; int *in, *begin; in =
#include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { if(argc != 2) return
#include <stdlib.h> #include <stdio.h> #include <math.h> #include <string.h> extern char **environ; int global_x =
#include stdafx.h #include stdio.h #include math.h #include stdlib.h void test (int a,int *b, int
The code: #include stdafx.h #include stdio.h #include math.h #include stdlib.h #include time.h int main()
Here is my perceptron implementation in ANSI C: #include <stdio.h> #include <stdlib.h> #include <math.h>
#include<stdio.h> #define N (sizeof(array) / sizeof(array[0])) main() { int array[5]={1,2,3,4,5}; int d; for(d=-1;d <=

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.