careercup1.2: reverse a C-Style String.

时间:2021-08-25 22:25:20

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;
}