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

I have come up with the following pointcut that I use for tracing method
how come when i use the following method in didLoad or willAppear with the
I’m having fun with EF and have come unstuck. Originally I used the following
How come when I use the following code, clicking on Click Here doesn't trigger
First time I've come to use collection_select in a project and I've hit a
I come from a mainly PHP background and make good use of the Apache
I use a lot of lists and arrays but I have yet to come
I come from a C++ background where I can use template mixins to write
I come from the asp.net world where we'd use an objectdatasource, hooked up to
I use an Ajax call to receive a response in hebrew. The results come

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.