Results 1 to 8 of 8

Thread: String Reverse...

  1. #1

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544

    String Reverse...

    I'm trying to create a string reverser, but the program doesn't read out the result....can anyone tell me what I'm doing wrong...

    Code:
    #include <iostream.h>
    #include <windows.h>
    
    void main(){
    	char TempString[255];
    	char TheString[255];
    	int StringLen;
    
    	cout<<"Please enter string to reverse: ";
    	cin>>TempString;
    	StringLen = strlen(TempString);
    	
    		
    	for(int a = 0; a > 255; a++)
        {
    		
    		TheString[a] = TempString[StringLen - 1];
    	}
    
    		
    	
    	for(int index = 0; index > 255; index++)
    	{
    		cout<<TheString[a];
    	}
    }
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  2. #2
    Member
    Join Date
    May 2001
    Location
    UK
    Posts
    40
    CyberCarsten

    The following line

    // do while a is greater than 255, but a equals zero therefore wouldn’t do anything.

    for(int a = 0; a > 255; a++)

    should read

    for(int a = 0; a < 255; a++)

    HTH

    hmm

    P.S After some thought

    #include <iostream.h>
    #include <windows.h>

    void main(){
    char TempString[255];
    char TheString[255];
    int StringLen;
    int a;
    int pause;
    cout<<"Please enter string to reverse: ";
    cin>>TempString;
    StringLen = strlen(TempString);


    for(int a = 0; a < 255; a++)
    {
    TheString[a] = TempString[StringLen -a];
    }


    for(int index = 0; index < StringLen +1 ; index++)
    {
    cout<<TheString[index];
    }
    cin >>pause;
    }
    Last edited by hmm; Aug 5th, 2001 at 12:11 AM.

  3. #3

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    Thanks!

    Now I got the result, but it's not letters...it's just alot of |[]

    ????
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  4. #4

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    It works!! Thank you very much!
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  5. #5
    Member
    Join Date
    May 2001
    Location
    UK
    Posts
    40
    CyberCarsten

    Have a look at the p.s of my first post ( I was modifying it has you were reading it ). I've changed some other parts



    hmm

  6. #6

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    It works perfect! Thanks!
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  7. #7
    Member
    Join Date
    May 2001
    Location
    UK
    Posts
    40

    Talking No problem

    Its nice to answer one, rather than always asking them

    hmm

  8. #8

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    Hehe! I feel the same way!
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width