array copying

This is a discussion on array copying within the C Programming forums, part of the General Programming Boards category; im trying to store my reverse array and call it back in main then print it out in main but ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    115

    array copying

    im trying to store my reverse array and call it back in main then print it out in main but it in the reverse function, the temp wont copy into the a array.
    Why?
    in the reverse function if i do a for loop and printf whats stored in the temp array then its the reverse of what the input is, however when i try to copy the temp array into the a array then print it out in main, it just prints out the input string. Its as if no copying has been done.

    what have i done wrong?
    Code:
    void reverse( char a[] )
    {
    	int i;
    	int n=0;
    	char temp[SIZE];
    
    	for( i=strlen(a); i >= 0; i--) {
    		temp[n] = a[i];
    		n++;
    	}
    	temp[n] = '\0';
    
    	strcpy( a, temp );
    }
    Last edited by kurz7; 05-07-2003 at 02:45 AM.
    there are only 10 people in the world, those who know binary and those who dont

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Okay to make your program work all you need to do is in your reverse function make it go from strlen(a) - 1 down. Remember array's are zero-based

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    115
    damn that sucked

    thanks for that
    there are only 10 people in the world, those who know binary and those who dont

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Copying Array to Vector Question
    By bengreenwood in forum C++ Programming
    Replies: 1
    Last Post: 06-01-2009, 04:00 PM
  2. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 08:31 AM
  3. Character Array copying
    By Drainy in forum C Programming
    Replies: 4
    Last Post: 03-15-2005, 10:43 AM
  4. Template Array Class
    By hpy_gilmore8 in forum C++ Programming
    Replies: 15
    Last Post: 04-12-2004, 12:15 AM
  5. Problem Copying char array
    By NullStyle in forum C++ Programming
    Replies: 2
    Last Post: 03-14-2004, 08:06 AM

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