Reverse() question?

This is a discussion on Reverse() question? within the C++ Programming forums, part of the General Programming Boards category; Code: #include<string.h> #include<iostream.h> const int max_len = 255; class string { public: void assign(const char* st) { strcpy(s, st); len ...

  1. #1
    TransparentMember correlcj's Avatar
    Join Date
    Jun 2002
    Posts
    378

    Reverse() question?

    Code:
    #include<string.h>
    #include<iostream.h>
    
    const int max_len = 255;
    
    class string	{
    public:
    	void assign(const char* st)
    	{	strcpy(s, st); len = strlen(st);	}
    	int length() const	{ return len;	}
    	void print() const
    	{ cout << s << "\nLength: " << len << endl;}
    	
    private:
    	char s[max_len];
    	int len;
    	reverse();
    	};
    
    int main(void)
    {
    	string one, two;
    	char three[40] = {"My name is Charles."};
    
    	one.assign("My name is Alan.");
    	two.assign(three);
    	cout << three;
    	cout << "\nLength: " << strlen(three) << endl;
    	if (one.length() <= two.length())
    		one.print();
    	else
    		two.print();
    	return 0;
    }
    Why won't this reverse in the private member s?
    Last edited by correlcj; 08-05-2002 at 07:11 PM.

  2. #2
    Registered User fletch's Avatar
    Join Date
    Jul 2002
    Posts
    176
    Why won't this reverse in the private member s?
    I don't understand your question. Can you be more specific? What are you trying to do?
    "Logic is the art of going wrong with confidence."
    Morris Kline

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    You may as well have asked the question:

    "Why doesn't this code render quake4 on my machine?" coz it yields the same answer.

    The answer is:

    "Because you haven't written any code to do it!"
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

  4. #4
    Registered User fletch's Avatar
    Join Date
    Jul 2002
    Posts
    176
    That's what I was thinking, but I thought that I might be missing something obvious.
    "Logic is the art of going wrong with confidence."
    Morris Kline

  5. #5
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Originally posted by Uraldor
    You may as well have asked the question:

    "Why doesn't this code render quake4 on my machine?" coz it yields the same answer.

    The answer is:

    "Because you haven't written any code to do it!"
    fool! just use

    cout << quake4 () << endl;

    hello, internet!

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You left out a few lines...

    Code:
    #include <quake4>
    int main ( )
    {
        Quake4 game;
        game.Run( );
        return 0;
    }
    There we go.

    Quzah.
    Hope is the first step on the road to disappointment.

  7. #7
    Registered User toaster's Avatar
    Join Date
    Apr 2002
    Posts
    161
    hmm, are you trying to reverse a string?
    if that is what you want, try this link:

    http://www.cprogramming.com/cboard/s...threadid=21882

    have fun.
    think only with code.
    write only with source.

  8. #8
    TransparentMember correlcj's Avatar
    Join Date
    Jun 2002
    Posts
    378

    Wink Are we havin ham for Xmas or what?

    >"Why doesn't this code render quake4 on my machine?" coz it yields the same answer. How in they hell did we go from reverse() to video games?
    Can someone break it down to me like i was a three year old because something just aint baking right here.

  9. #9
    Registered User toaster's Avatar
    Join Date
    Apr 2002
    Posts
    161
    if the function reverse() does not reverse a string, what is it supposed to do?
    think only with code.
    write only with source.

  10. #10
    Green Member Cshot's Avatar
    Join Date
    Jun 2002
    Posts
    892
    You don't just prototype your function like this:
    reverse();

    You need to specify the return value too. Also defining your function might help. It's supposed to do something right?

    EDIT- Oh! Are you trying to reverse the string in your private section of the code? You can't run code there. That's only for defining your class. If you want to reverse your string on a created object, you may want to do it in the constructor.
    Last edited by Cshot; 08-06-2002 at 06:04 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. gethostbyaddr() reverse lookups failing (???)
    By Uncle Rico in forum C Programming
    Replies: 9
    Last Post: 08-19-2005, 09:22 AM
  2. I'm not ask for ENTIRE program, only 1 Question !
    By Th3-SeA in forum C Programming
    Replies: 10
    Last Post: 10-01-2003, 12:33 PM
  3. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  4. Replies: 7
    Last Post: 03-18-2003, 02:32 PM
  5. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 08:22 PM

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