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-29 16:56

>>10

Symta:

f !?.??+1 [ø@X]


Haskell:

module Main
where

import List
import Control.Arrow

type Comparator a = (a -> a -> Ordering)

ascending :: (Ord a) => (b -> a) -> Comparator b
ascending f x y = compare (f x) (f y)

descending :: (Ord a) => (b -> a) -> Comparator b
descending = flip . ascending

secondary :: Comparator a -> Comparator a -> Comparator a
secondary f g x y = case f x y of {
                    EQ -> g x y;
                    z  -> z; }

-- Returns a list of unique elements together with their frequency. Listed in decreasing order of frequency, followed by
increasing order of the elements.
count :: (Ord a) => [a] -> [(a, Int)]
count = map (head &&& length) . sortBy (descending length `secondary` ascending head) . group . sort

main :: IO ()
main = interact $ unlines . map (\(x, y) -> (take 20 $ x ++ repeat ' ')  ++ " : " ++ show y) . count . words

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