《c程序设计语言》读书笔记--反转字符串

#include "stdio.h"

#define Num 100

void reverse(char words[])
{
  int i, j, c, n=0;
  while(words[n]!='\0')
  n++;

  for(i=0,j=n-1;i<j;i++,j--)
  {
    c = words[i];
    words[i] = words[j];
    words[j] = c;
  }
}


int main()
{
    char words[Num]={0};

    int c,i = 0;

    while((c = getchar()) != EOF)
          {
              words[i] = c;
              i++;
          }
    reverse(words);

    printf("%s\n",words);

    return 0;

}


反转字符串。

posted @ 2014-10-28 23:02  司空格子Ored  阅读(196)  评论(0编辑  收藏  举报