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

Pages: 1-4041-

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-14 20:37

I lol'd.

Name: Anonymous 2011-03-14 20:42

this code isnt even mine, just trying to help out a friend

Name: Anonymous 2011-03-14 20:46

Change

for (i = 0 ; i < n ; i-- )
strout[n-i-1] = strin[n];


to

for (i = 0 ; i < n ; i++)
strout[i] = strin[i];


You're welcome now fuck off.

Name: Anonymous 2011-03-14 20:48

>>4
Storing the data in the correct variables left as an exercise to the autists.

Name: Anonymous 2011-03-14 20:50

>>1-5
seg̕me͡n̛tat҉io҉ņ ͢f̸ault҉

Name: Anonymous 2011-03-14 20:56

[code]// copy the null string terminator[/spoiler]
Don't you just love it when the comments are incorrect

Name: Anonymous 2011-03-14 20:57

>>7
code/spoiler? What the hell was I thinking?

Name: Anonymous 2011-03-14 21:12

sill wont reverse the string to palindrome

Name: Anonymous 2011-03-14 21:19

>>9
Can you really not see why that is, or are you pulling my leg?

Name: Anonymous 2011-03-14 21:19

>>10
im fucking blind

Name: Anonymous 2011-03-14 21:20

>>10
i really dont know lol

Name: Anonymous 2011-03-14 21:27

just tell me so i can get out of here, please.

Name: Anonymous 2011-03-14 21:31

VIOLATE MY ANUS

Name: Anonymous 2011-03-14 21:35

>>14
>.>

Name: IHBT 2011-03-14 21:45

>>13
Future PHP programmer detected!
void strrvr(char strout[], char strin[])
// just because C gives shitty names to it's library functions
// doesn't mean you should. It's string_reverse, not strrvr
{
int n = strlen( strin ); // a rare correct line
int i = n; // notice that we need to initialise i
strout[i] = strout[n]; // copy the null string terminator
for (i = 0 ; i < n ; i++) // you want to loop up from i not down
strout[i] = strin[n-i-1]; // you were just writing a \0 to each element in strout
}

Name: Anonymous 2011-03-14 21:54


const int buf_len = 100;
char in[buf_len] = "autism", out[buf_len];
int in_len = strlen(in), i = 0;
for(i = 0; i < in_len; i++)
     #some forced indentation for good measure
     out[i] = in[(in_len - i) + 1]; #fucking magnets here
out[i] = '\0';

or something

Name: Anonymous 2011-03-14 21:54

>>16
this works however, i adds a lot of junk to the end of palindrom

Name: Anonymous 2011-03-14 21:54

>>18
palindrome

Name: Anonymous 2011-03-14 21:55

How do we tell if a palidrome is sorted or not?

Name: Anonymous 2011-03-14 21:59

>>18
Erm, if there is junk after the null, it is because it was there  to begin with.

Name: Anonymous 2011-03-14 22:03

>>21
its some random ass question marks, letters, and smiley faces

Name: Anonymous 2011-03-14 22:30

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

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

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


void string_reverse(char strout[], char strin[])

{
int n = strlen( strin );
int i = n;
strout[i] = strout[n];
for (i = 0 ; i < n ; i++)
strout[i] = strin[n-i-1];
}

Name: Anonymous 2011-03-14 23:05

>>16

You shouldn't be using C++ comments

C++ users use C++ comments

This behavior is unscientific and ultimately destructive.

Name: Anonymous 2011-03-14 23:24

>>24
Shut the fuck up. /**/ is a stupid syntax.

Name: Anonymous 2011-03-14 23:38

>>24-25
Having ; as statement separator instead of single-line comment marker is stupid.

Name: Anonymous 2011-03-14 23:41

>>26
AUTISMO

Name: Anonymous 2011-03-14 23:51

>>24
See: >>27.

Name: Anonymous 2011-03-15 0:20

still cant figure out why i have junk at the end of palindrome

Name: Anonymous 2011-03-15 3:02

>>24
C99 IN YOUR FACE

Name: IHBTT 2011-03-15 3:07

>>16
it's library functions
What about it is library functions?

Name: Anonymous 2011-03-15 7:45

>>16

int n = strlen( strin ); // a rare correct line

It's not correct, strlen returns a size_t.

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 */
}

Name: Anonymous 2011-03-15 10:34

>>32
then what should it be

Name: Anonymous 2011-03-15 11:44


static void strrvr(const char *in, char *out, ssize_t n)
{
        int i;
        for (i = 0, n-=2; n >= 0; ++i, --n)
                out[i] = in[n];
        out[i] = '\0';
}

#ifdef TEST

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
        char in[] = "HAX NY AMUS";
        char out[sizeof in];

        strrvr(in, out, sizeof out);
        puts(out);

        return EXIT_SUCCESS;
}
#endif

Name: Anonymous 2011-03-15 12:47

>>34

Why am I not surprised you should ask that,
size_t n = strlen( strin );

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;
  }

Name: Anonymous 2011-03-15 14:03

>>37
Probably doable faster by abusing the stack, but what's the point with putting 2 underscores before the variable names?

Name: Anonymous 2011-03-15 14:11

>>36
To all faggots who think size_t is a separate type and not an integer:
size_t is just a typedef, it even says so in the C99 standard

Name: Anonymous 2011-03-15 14:20

>>39
To all faggots who think int == integer:
YHBT YHBT YHBT YHBT YHBT YHBT YHBT YHBT YHBT YHBT YHBT YHBT

Name: Anonymous 2011-03-15 15:15

>>39
It's an unsigned integer, and size_t is portable, you cock-sucking ``faggot''. IHBT

>>38
GNU/Style.

Name: Anonymous 2011-03-15 16:40

>>39

It's unsigned, ``faggot''.

Name: Anonymous 2011-03-15 17:06

>>37
const __attribute__((always_inline) (const)) static inline void
strrvr (const char * restrict ____i, char * restrict ____o)
  {
    size_t ____p = strlen(____i);

    for (;____p & 7;____i++,____p--)
      *(____o + ____p - 1)=*____i;

    for (; ____p; ____i+=8, ____p-= 8)
      *(uint64_t*) (____o + ____p - 8)  = __builtin_bswap64(*(uint64_t*) ____i);
  }

Name: Anonymous 2011-03-15 17:34

>>43
What the fuck.

Name: Anonymous 2011-03-15 17:53

>>43
Autism ABUSE.

Name: Anonymous 2011-03-15 19:33

dicks

Name: Anonymous 2011-03-16 4:25

dicks

Name: Anonymous 2011-03-16 4:28

fuque

Name: Anonymous 2011-03-16 4:30

f

Name: Anonymous 2011-03-16 4:32

f

Name: Anonymous 2011-03-16 5:23

>>19
The notation is C-x s. Without the ^.

Name: Anonymous 2011-03-16 5:26

anus dick = take 4

Name: Anonymous 2011-03-16 9:56

>>52
good song = take 5

VALID HAKAL CODE

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