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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:24:56+00:00 2026-05-31T07:24:56+00:00

I am trying to change the value of my char array[10] within a switch

  • 0

I am trying to change the value of my char array[10] within a switch statement such that, if we have case 1, my char array[10]=”january”, or if we have case 2, then array[10]=”february” and so on. The problem is that i get error message, and i know that I am doing something wrong. any help will be very appreciated. here is my switch statement written in Dev-C++.

char month[10];
switch (i)
{
 case 1:
       month[10]="January";
      cout<<month<<endl;
      break; 
 case 2:
       month[10]="February";
      cout<<month<<endl;
      break;
} 
  • 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-31T07:24:56+00:00Added an answer on May 31, 2026 at 7:24 am

    When you create strings like "January" or "December" the compiler is generating a const char * which points to a constant array of characters that has a 0 at the end the integer not the character.

    Your code is trying to assign "January"‘s address to the 11th element in the array, which it doesn’t have because arrays start at 0.

    This has a couple problems, First, the elements of month[] are characters, not character pointers. Second, arrays start at 0 so you were looking to use month[9], though that still would have been wrong.

    What you are looking to do is copy each character into the array, there are functions that do this like strcpy but try it with a for loop first to give yourself a better sense of what is going on.

    Another way to solve this problem, and probably the way you’re after is to change month from a character array of a fixed size, to a char * that way you can use your earlier method of month = "January" its how I would prefer to do it myself, because it only uses up as much memory as I need and the syntax is cleaner, though you should know how to do both methods.

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

Sidebar

Related Questions

I am trying to change the value of a static char * I define
I'm trying to change the value of a dojo tree to display the correct
I am trying to programmatically change a value of a wxRadioButton in a way
I'm trying to use jQuery to change the value of button.kill . However I
I'm trying to change the color of a UILabel depending on the .text value
I'm trying to execute this function when a select list's (LevelId0) value change but
I am trying to make a numerical value, say 5000, quickly change to another
I have simplified an issue that I've been having trying to isolate the problem,
I'm trying to compare a character array against a string like so: const char
I'm trying to convert a struct to a char array to send over the

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.