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

C reversing a string

Name: Anonymous 2012-10-29 12:00

Why does "printf("%c, reverse")" just put out "aggiN", but ("%s, reverse") outside of the loop put out "aggiNNigga" when it should do the same?

int main(int argc , char* argv [ ] ) {

    int i=0;
    int c;
    int a=0;
    char string[]="Nigga";
    char reverse[20];

    i=sizeof(string);
    printf("%d\n", (i-1));

        for(c=i-2;c>=0;c--)
        {
            reverse[a]=string[c];
                        printf("%c", reverse[a]);
                        a++;

        }
    printf("\n%s", reverse);
    return 0;
}

Name: Anonymous 2012-10-31 11:41

>>40
define ⌽

Name: LISPPER 2012-10-31 11:56

>>41
(define ⌽ reverse)

Name: Anonymous 2012-10-31 12:01

>>42
APL has an operator for reverse? Terrible!

Name: Anonymous 2012-10-31 12:02

>>43
If you think about it it's a very common operation, especially if you're doing purely functional tail-recursive stuff.

Name: Anonymous 2012-10-31 12:03

>>44
justify.

Name: Anonymous 2012-10-31 12:09

>>45
Write a tail-recursive lisp/scheme function that conses each element of a list with its position, i.e. (a b c) becomes ((a . 0) (b . 1) (c . 2)).

Name: Anonymous 2012-10-31 12:13

Contribooting Javascript.
function reverse(string){
    i=string.length;
    o="";
    while(i>-1){
        o+=string.substr(i,1);
        i--;
    }
    return o;
}

Name: Anonymous 2012-10-31 12:18

>>46

yoba N Ys [X@Xs] = yoba N+1 [@Ys [N X]] Xs
    ;_ Ys _ = Ys> 0

Name: Anonymous 2012-10-31 12:19

>>48
And now in real lisp...

Name: Anonymous 2012-10-31 12:21

>>49

(PROGN
 (LOCALLY
  (DECLARE (SPECIAL |st|::|glb-yoba|))
  (SETF (SYMBOL-FUNCTION '|st|::|glb-yoba|)
          ((LAMBDA (|st|::|yoba| |st|::|r|)
             (PROGN
              (SETQ |st|::|yoba|
                      (NAMED-FN |st|::|yoba|
                          (|st|::G6273& |st|::G6274& |st|::G6275&)
                        ((LAMBDA (|st|::|u6276&|)
                           ((LAMBDA (|st|::N)
                              ((LAMBDA (|st|::|Ys|)
                                 (IF (XS? |st|::G6275&)
                                     ((LAMBDA (|st|::X)
                                        ((LAMBDA (|st|::|Xs|)
                                           (FUNCALL |st|::|yoba|
                                                    (|st|::|glb-+| |st|::N 1)
                                                    (|st|::|glb-suf|
                                                     (CL-LST |st|::N |st|::X)
                                                     |st|::|Ys|)
                                                    |st|::|Xs|))
                                         (|st|::|glb-ltl| |st|::G6275&)))
                                      (|st|::|glb-lhd| |st|::G6275&))
                                     (FUNCALL |st|::|u6276&|)))
                               |st|::G6274&))
                            |st|::G6273&))
                         (LAMBDA ()
                           ((LAMBDA (|st|::|Ys|) |st|::|Ys|) |st|::G6274&)))))
              (SETQ |st|::|r| |st|::|yoba|)))
           NIL NIL)))
 NIL)

Name: Anonymous 2012-10-31 12:21


String.prototype.reverse=function(){
    i=this.length;
    o="";
    while(i>-1){
        o+=this.substr(i,1);
        i--;
    }
    return o;
}


Even better Javascript.


"asdf".reverse(); //"fdsa"
faggot="reggin";
faggot.reverse(); //"nigger"

Name: Anonymous 2012-10-31 12:28

>>51
> var strings = ["hello", "world"];
for (var i = 0; i < strings.length; ++i)
    console.log(strings[i].reverse());
olleh
olleh
olleh
olleh
olleh
olleh
...

Name: Anonymous 2012-10-31 12:35

>>52
What's wrong with that?

Name: Anonymous 2012-10-31 12:53

>>52
String.prototype.reverse=function(){
    this.i=this.length;
    this.o="";
    while(this.i>-1){
        o+=this.substr(this.i,1);
        this.i--;
    }
    return this.o;
}

Name: Anonymous 2012-10-31 12:55

>>54
>o+=this.substr(this.i,1);
Should be
>this.o+=this.substr(this.i,1);

Name: Anonymous 2012-10-31 13:07


(reversen "next!")

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