[ create a new paste ] login | about

Link: http://codepad.org/nvJL67nU    [ raw code | output | fork ]

C, pasted on Jan 13:
#include <stdio.h>
#include <string.h>
int main() {
  char orig[] = "abcdef";
  char tmp, *p, *q;
  //int s;
  char *end;
  
  printf("orig: %s, orig = %p\n", orig, orig);
  for (p = orig; *p; p++)
    printf("%c(%p)", *p, p);
  putchar('\n');
  end = p;
  
  //s = strlen(orig);
  for (p = orig, q = end - 1; p < q; p++, q--) {
    tmp = *p;
    *p = *q;
    *q = tmp;
  }

  printf("orig: %s, orig = %p\n", orig, orig);
  for (p = orig; *p; p++)
    printf("%c(%p),", *p, p);
  putchar('\n');
  return 0;
}


Output:
1
2
3
4
orig: abcdef, orig = 0xbf475f31
a(0xbf475f31)b(0xbf475f32)c(0xbf475f33)d(0xbf475f34)e(0xbf475f35)f(0xbf475f36)
orig: fedcba, orig = 0xbf475f31
f(0xbf475f31),e(0xbf475f32),d(0xbf475f33),c(0xbf475f34),b(0xbf475f35),a(0xbf475f36),


Create a new paste based on this one


Comments: