Geek Quiz
< >

Apr 22 2004 Kelly Norton

Here’s some geeky fun for everyone. I was reading some random blog entry at some random url the other day. There someone was describing a question they had been asked at a job interview. A solution did not immediately come to mind, so I figured I was lucky to have never been asked a similar question. I didn’t linger long at the site, but the question would not go away. Finally when I caught myself staring at the tea pot searching for an easy solution long after the tea was ready, I decided to take out a piece of paper and exorcise my curiosity. I reluctantly admit that it took me longer than would have been acceptable to reach a solution that I liked, but it was a fun puzzle. And most importantly, I can move on with my day. But before I do, I wanted to pos[te] the question here for the annoyance … er … enjoyment of others.

The challenge:

Write a function that takes in two buffers that are NULL padded. The function should swap and reverse the data in the two buffers. Assume the two buffers are equal in length (not the data, of course). Here is an example.

before
buffer #1: h i \0 \0 \0 \0
buffer #2: w o r l d \0
after
buffer #1: d l r o w \0
buffer #2: i h \0 \0 \0 \0

one might start something like:

void reverse_swap(char* buffer0,char* buffer1) {
    …
}
0
0