我试图通过调用函数来输出字符串的反转。我认为我的反向功能有问题。我不断收到错误消息“并非所有控制路径都返回值”。
#include<iostream>
using std::cout;
using std::endl;
using std::cin;
int LengthofString( char *); // declaring prototype for length of the string
int ReverseD(char *);
int main()
{
char string1[100];
cout<<"Enter a string: ";
cin>>string1;
cout<<"Length of string is "<<LengthofString(string1)<<endl<<ReverseD(string1)<<endl;
system("PAUSE");
return 0;
}
int LengthofString( char *x)
{
int index;
for(index = 0; *x!='\0';x++,index++);
return index;
}
int reverse(char* y)
{
int ii, n;
n = LengthofString(y);
for(ii=0; ii<n/2;ii++) {
char temp;
temp = y[ii];
y[ii] = y[n - ii - 1];
y[n - ii] = temp;
return temp;
}
}