主题:字符串输入
字符串排序问题,循环体出现问题,不知怎样才能控制退出循环麻烦,各位帮我改一下,谢谢
#include<iostream>
#include<string>
using namespace std;
void sort(char*[],int);
int main()
{
char s[10]=" ";
char *array[50];
int count=0;
cout<<"Please enter the string which should be sorted(0 to end):"<<endl;
cin>>s;
while(s!=0)
{
array[count++]=s;
cin>>s;
}
sort(array,count);
cout<<"After sorting :"<<endl;
for(int i=0;i<count;i++)
cout<<array[i];
cout<<endl;
return 0;
}
void sort(char *a[50],int count)
{
char *temp;
for(int i=0;i<count;i++)
{
for(int j=i+1;j<count;j++)
{
if(strcmp(a[j],a[i])<0)
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
}
#include<iostream>
#include<string>
using namespace std;
void sort(char*[],int);
int main()
{
char s[10]=" ";
char *array[50];
int count=0;
cout<<"Please enter the string which should be sorted(0 to end):"<<endl;
cin>>s;
while(s!=0)
{
array[count++]=s;
cin>>s;
}
sort(array,count);
cout<<"After sorting :"<<endl;
for(int i=0;i<count;i++)
cout<<array[i];
cout<<endl;
return 0;
}
void sort(char *a[50],int count)
{
char *temp;
for(int i=0;i<count;i++)
{
for(int j=i+1;j<count;j++)
{
if(strcmp(a[j],a[i])<0)
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
}