C reversing a string
1
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;
}
33
Name:
Anonymous
2012-10-29 20:36
>>30
I know I had a brain fart, thinking about typeof, I was so embarrassed with the aberration I just said that I closed the computer and went outside
34
Name:
Anonymous
2012-10-30 0:09
35
Name:
Anonymous
2012-10-30 2:38
>>33
I know that feel bro
36
Name:
Anonymous
2012-10-30 12:42
Now in D
string reverse(string str)
{
import std.range;
return retro(str);
}
37
Name:
Anonymous
2012-10-30 18:09
>>36
Go to bed,
Alexandrescu .
38
Name:
Anonymous
2012-10-31 9:21
Someone have the Fortran code to this?
39
Name:
Anonymous
2012-10-31 11:05
>>15
try harder.
Symta:
reverse X = f [??@?] X
Haskell:
reverse = foldl (flip (:)) []
40
Name:
Anonymous
2012-10-31 11:39
>>39
What the fuck are you trying to prove?
Here it is in APL:
⌽
According to your logic, APL is a better language than Symta...?
41
Name:
Anonymous
2012-10-31 11:41
42
Name:
LISPPER
2012-10-31 11:56
43
Name:
Anonymous
2012-10-31 12:01
>>42
APL has an operator for reverse? Terrible
!
44
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.
45
Name:
Anonymous
2012-10-31 12:03
46
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)).
47
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;
}
48
Name:
Anonymous
2012-10-31 12:18
>>46
yoba N Ys [X@Xs] = yoba N+1 [@Ys [N X]] Xs
;_ Ys _ = Ys> 0
49
Name:
Anonymous
2012-10-31 12:19
>>48
And now in real lisp...
50
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)
51
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"
52
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
...
53
Name:
Anonymous
2012-10-31 12:35
>>52
What's wrong with that?
54
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;
}
55
Name:
Anonymous
2012-10-31 12:55
>>54
>o+=this.substr(this.i,1);
Should be
>this.o+=this.substr(this.i,1);
56
Name:
Anonymous
2012-10-31 13:07
(reversen "next!")
Newer Posts