字符串排序排序C++

例如输入:Hello!
Good morning!
I'm AA.
Are you BB?
排序后输出:Are you BB?
Good morning!
Hello!
I'm AA.
要求:输入不定个数字符串,排序后,按字符串从小到大的顺序输出。每行字符有空格、数字、字母等符号组成。

用strcmp就可以进行比较了

#include <stdio.h>
#include <string.h>
int main()
{
    char s[100][50] = {0};
    char p[50];
    int n=0;
    while(scanf("%[^\n]",s[n]) != EOF)
    {
        n++;
    }
    for(int i=0;i<n-1;i++)
        for(int j=0;j<n-i-1;j++)
        {
            if(strcmp(s[j],s[j+1]) > 0)
            {
                strcpy(p,s[j]);
                strcpy(s[j],s[j+1]);
                strcpy(s[j+1],p);
            }
        }
    for(int i=0;i<n;i++)
        printf("%s\n",s[i]);
    return 0;
}