Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Segment Violation

Name: fsdf 2011-03-14 20:32

I cant find the last segment violation, I think its in line 26 but I dont know what it should be.

#include "stdio.h"
#include "string.h"

// function prototypes
void strrvr( char outstr[] , char instr[] );

// driver
int main()
{
char outstr[100];
char instr[100]="emordnilap";
strrvr(outstr, instr);
printf( "%s\n", outstr );
return( 0 );
}

// strrvr function
void strrvr(char strout[], char strin[])
{
int i;
int n = strlen( strin );
strout[i] = strout[n]; // copy the null string terminator
for (i = 0 ; i < n ; i-- )
strout[n-i-1] = strin[n];
}

Name: Anonymous 2011-03-15 8:15

GNU/Optimized


   /*This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>;.  */

const __attribute__((always_inline)) static inline void
strrvr(char * __i,
    char * __o)
{
    size_t __p;

    for ( __p=strlen(__i)-1;*__i!='\0';__i++,__p-- )
        {
            *( __o+__p )=*__i;
        }
   /* todo: make sure __o gets null terminated */
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List