Some wierd errror I don't understand

This is a discussion on Some wierd errror I don't understand within the C++ Programming forums, part of the General Programming Boards category; I want to make a simple singly linked list. The conversion constructor in the class "slist" is slist(const char* c) ...

  1. #1
    Registered User Hexadakota's Avatar
    Join Date
    Jan 2008
    Posts
    21

    Some wierd errror I don't understand

    I want to make a simple singly linked list. The conversion constructor in the class "slist" is slist(const char* c) and I want it to just take a string, reverse it, and prepend it so that each letter in the string is a node in the linked list.

    Conversion Constructor

    Code:
    slist::slist(const char* c)
    {
         int i;
         int len = strlen(c);
         char temp;
         
         for (i = 0; i < len/2 ; i++){     //Stops when half the string is reached
    		temp = c[i];                       
    		c[i] = c[len-1-i];                 //First char is set to last
    		c[len-1-i] = temp;                 //Last char is set to first
    	 }
    
         
         for(i = 0; i < len; i++)
                 prepend(c[i]);
    }
    The error I'm getting says that on these lines...

    Code:
    		c[i] = c[len-1-i];                 //First char is set to last
    		c[len-1-i] = temp;                 //Last char is set to first
    "assignment of read-only location"

    What does that mean? Tell me if you need more code like the class or any other functions.

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,614
    The pointer c is of type const char, so you can't modify the contents where it's pointing at.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User Hexadakota's Avatar
    Join Date
    Jan 2008
    Posts
    21
    oh....

    ....duh

  4. #4
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    SGI (and probabaly Boost) already has an slist.

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,304
    Instead of reversing the string, why don't you append instead of prepending?
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I could not understand this question
    By enggabhinandan in forum C Programming
    Replies: 3
    Last Post: 10-22-2006, 05:17 AM
  2. Replies: 21
    Last Post: 10-14-2006, 04:38 AM
  3. Need software to help to understand C source code
    By Kincider in forum C++ Programming
    Replies: 1
    Last Post: 09-28-2006, 09:44 PM
  4. Replies: 13
    Last Post: 08-24-2006, 12:22 AM
  5. Need help to understand x["AC"] in the following code
    By jcourcel in forum C Programming
    Replies: 11
    Last Post: 06-06-2006, 01:13 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21