careercup1.2: reverse a C-Style String.

Write code to reverse a C-Style String. (C-String means that “abcd” is represented as
!ve characters, including the null character.)

 

#include <iostream>
#include <vector>
#include <set>
#include <cmath>
#include <fstream>

using namespace std;

void main(int argc, char** argv)
{
	char s[] = "afljldsafjlajfl";
	char * p=s,* q=s;
	while(*q!='\0') {
		++q;
	}
	--q;
	char tmp;
	while(p<q) {
		tmp = *p;
		*p = *q;
		*q = tmp;
		++p;
		--q;
	}
	cout<<s<<endl;
}


 

posted @ 2013-01-31 09:56  西施豆腐渣  阅读(125)  评论(0编辑  收藏  举报