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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:46:29+00:00 2026-05-12T18:46:29+00:00

How come when I use the following method, to be used to convert all

  • 0

How come when I use the following method, to be used to convert all the characters in a string to uppercase,

while (*postcode) {
    *postcode = toupper(*postcode);

    postcode++;
}

Using the following argument works,

char wrong[20];
strcpy(wrong, "la1 4yt");

But the following, doesn’t, despite them being the same?

char* wrong = "la1 4yt";

My program crashes in an attempt to write to an illegal address (a segfault, I presume). Is it an issue with not mallocing? Not being null-terimanted? It shouldn’t be…

Through debugging I notice it crashes on the attempt to assign the first character as its uppercase.

Any help appreciated!

  • 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-12T18:46:29+00:00Added an answer on May 12, 2026 at 6:46 pm
    char* wrong = "la1 4yt";
    

    This declares a pointer to a string constant. The constant cannot be modified, which is why your code crashes. If you wrote the more pedantic

    const char* wrong = "la1 4yt"; // Better
    

    then the compiler would catch the mistake. You should probably do this any time you declare a pointer to a string literal rather than creating an array.

    This, on the other hand, allocates read/write storage for twenty characters so writing to the space is fine.

    char wrong[20];
    

    If you wanted to initialize it to the string above you could do so and then would be allowed to change it.

    char wrong[20] = "la1 4yt"; // Can be modified
    char wrong[]   = "la1 4yt"; // Can be modified; only as large as required
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How come when I use the following code, clicking on Click Here doesn't trigger
I have an Entity with the following property: [ScriptIgnore] public DateTime Date { get
I have a corpus of token-index based documents which offers a query method. The
I've got an ASP.NET MVC method (v3.0 on .NET 4.0) set up like the
I have been working on a method to sync core data stored in an
Good day! I am a little bit confused. I want to use a calendar
I have successfully implemented a restful service that works with my own client. Now,
Here is a description of my problem: I have got TabActivity consists of three
I'm trying to integrate an application with Facebook Chat in C#. Facebook recommends the
After an discussion at work, I still do not have an satisfying answer about

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.