문자열 뒤집기(reverse)

2014. 1. 21. 09:54Programing/C Language

#include <stdio.h>

#include <stdlib.h>

#include <string.h>


void reverse(char * pStr);

 

void main()

{

  char str[100];

  printf("Input string : ");

  gets(str);

  reverse(str);

  printf("Reverse sting : %s\n", str);

  system("PAUSE");

}

 

void reverse(char * pStr)

{

  int nLen = strlen(pStr);

  int nLoop = 0;

  char * tmp = NULL;

  for(nLoop=0; nLoop<nLen/2; nLoop++)

  {

    tmp = *(pStr+nLoop);

    *(pStr+nLoop) = *(pStr+nLen-1-nLoop);

    *(pStr+nLen-1-nLoop) = tmp;

  }

}