Thread: replace the "*" in the above string with " ", a single space character using ANSI C??

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Smiley10 View Post
    obaid's code is modifying a string literal too which are constant.

    Why are there no standard restrictions on modifying string literals?
    In trivial cases, it would be possible for the compiler to detect it, but in anything but trivial cases (e.g. when a function takes a char * as a parameter, and that char * happens to be a pointer to a literal).

    It's not just obaid's code that does so, by the way, several of the other examples do too. Maxorators doesn't - but it also doesn't match the original poster's question - and by the way, we haven't seen any post from the OP for a while.... Perhaps the lesson ended? :-)

    --
    Mats

  2. #2
    Registered User
    Join Date
    Jul 2006
    Posts
    10
    Quote Originally Posted by matsp View Post
    In trivial cases, it would be possible for the compiler to detect it, but in anything but trivial cases (e.g. when a function takes a char * as a parameter, and that char * happens to be a pointer to a literal).

    It's not just obaid's code that does so, by the way, several of the other examples do too. Maxorators doesn't - but it also doesn't match the original poster's question - and by the way, we haven't seen any post from the OP for a while.... Perhaps the lesson ended? :-)

    --
    Mats
    Thank you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. RicBot
    By John_ in forum C++ Programming
    Replies: 8
    Last Post: 06-13-2006, 06:52 PM
  3. Program using classes - keeps crashing
    By webren in forum C++ Programming
    Replies: 4
    Last Post: 09-16-2005, 03:58 PM