东北人在上海oshcn.blog.chinaunix.net
engelbert
全部博文(55)
2011年(27)
2009年(3)
2008年(25)
xuequans
cynthia
浪花小雨
李小小渔
常白kiri
losehapp
zhangjin
分类: LINUX
2008-04-24 09:13:29
/* * ===================================================================================== * * Filename: up_to_down.c * * Description: 字符串逆序: abcd <==> dcba * * Version: 1.0 * Created: 04/23/08 23:08:51 * Revision: none * Compiler: gcc * * Author: Engelbert (mr), engelbert@yahoo.cn * Company: WAVETEK * * ===================================================================================== */#include <stdlib.h>#include <string.h>#include <stdio.h>#define MAX_BUF 80 /* */char buffer[MAX_BUF]="sdfaighlkj";/* * === FUNCTION ====================================================================== * Name: main * Description: * ===================================================================================== */int main ( int argc, char *argv[] ){ int length=0; int i=0; int center=0; char temp; int flag; printf ( "%s\n", buffer ); length=strlen(buffer); printf ( "length:%d\n", length ); center=length/2; flag=(length%2)?center:(center+1); //odd or even printf ( "flag:%d\n", flag ); for(i=0;i<flag;i++){ temp=buffer[0+i]; buffer[0+i]=buffer[length-1-i]; buffer[length-1-i]=temp; } printf ( "%s\n", buffer ); return EXIT_SUCCESS;} /* ---------- end of function main ---------- */
上一篇:strtok函数实例
下一篇:设置Debian中文环境
登录 注册