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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:02:55+00:00 2026-06-12T02:02:55+00:00

Thanks for your attention… I am really confused.. Why I cannot convert char type

  • 0

Thanks for your attention… I am really confused.. Why I cannot convert char type to uppercase with toupper when I gave the char an array… like this “char drh[1]”?

Here is my code.. This code is not finished yet.. I’m stuck in the midway.

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <ctype.h>

using namespace std;
int main()
{
    char nama[50], gender[6], drh[1];
    int tahun_l, usia;
    float berat, tinggi, berat_i;

    printf("Masukkan Data Anda\n\n");
    // INPUT ZONE

    //First
    printf("Nama\t\t\t\t: ");
    scanf("%[^\n]", &nama);

    printf("Tahun Lahir (yyyy)\t\t: ");
    scanf("%d", &tahun_l);

    printf("Gol Darah (A/B/C)\t\t: ");
    scanf("%s", &drh);

    system("cls");

    //Second
    printf("Masukkan Data Anda\n\n");

    printf("Nama\t\t\t\t: %s\n", nama);
    fflush(stdin);

    printf("Tahun Lahir (yyyy)\t\t: %d\n", tahun_l);
    fflush(stdin);

    printf("Gol Darah (A/B/O)\t\t: %s\n", drh);
    drh = toupper(drh); //not working
    fflush(stdin);

    printf("Jenis Kelamin (Pria/Wanita)\t: ");
    scanf("%s", &gender);

    printf("Berat Badan (kg)\t\t: ");
    scanf("%f", &berat);

    printf("Tinggi Badan (cm)\t\t: ");
    scanf("%f", &tinggi);

    //FORMULA ZONE
    usia    = 2008 - tahun_l;
    berat_i = tinggi - 100 - (0.1 * (tinggi - 100));
    //OUTPUT ZONE
    printf("\n%s, berdasarkan data yang Anda masukkan,\n", nama);
    printf("Anda berjenis kelamin %s, saat ini Anda berusia %d tahun,\n", gender, usia);
    printf("Berat badan = %.2f kg, tinggi badan = %.2f cm, golongan darah = %s \n", berat, tinggi, drh);
    printf("\nBerat badan ideal adalah %.2f", berat_i);

    getche();
    return 0; 
}
  • 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-12T02:02:57+00:00Added an answer on June 12, 2026 at 2:02 am

    The toupper function works on a single character, not on a string. If you need to convert the whole string to upper case, you need to use a loop:

    for (char *p = drh ; *p ; *p = toupper(*p), p++)
        ;
    

    However, your drh buffer does not have a sufficient length: it must have 2 characters to fit the null terminator:

    char nama[50], gender[6], drh[2];
    //  Add 1 char for terminator ^---- HERE
    

    Moreover, since you know that drh is a single character, you can use

    *drh = toupper(*drh);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi and thanks for your attention. First some background on the question: I have
Thanks for your help! I'd like to output all companyName entries that have uploads
Thanks for your attention and time. I need your opinion on an basic architectural
Thanks for your attention and time. I'm modifying an existing JavaScript but can't understand
Thanks for your time and attention. I have ajaxtookit Autocomplete and requriment is to
First of all, thanks in advance for your attention : I am pretty noob
I have several newbie questions about EC2, thanks for your attention, 1) why EC2
Thanks for your attention, and sorry for mi English :S I'm using JPA 2.0
thanks for your attention and precious time. Please mention some free javascrpt obfuscator software
thanks for your reading. I am trying to modify Jquery Nivo Zoom plugin to

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.