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 13:32

>>33
OMG OPTIMIZED that for you.
const __attribute__((always_inline) (const)) static inline void
strrvr (const char * restricted __i, char * restricted __o)
  {
    size_t __p;
   
    for (__p=strlen(__i)-1;*__i;__i++,__p--)
      *(__o+__p)=*__i;
  }

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