编写一个函数,用于去掉字符串尾部的空格符
#include <iostream>
using namespace std;
void delSpace(char *str)
{
unsigned int size = 0;
while(*str != '\0')
{
size++;
str++;
}
if(size > 0)
{
str--;
if(*str == ' ')
{
*str = '\0';
}
}
}
int main()
{
char testStr[] = "ab cd ";
cout << (int)testStr[5] << endl;
delSpace(testStr);
cout << testStr << endl;
cout << (int)testStr[5] << endl;
}