一个C++程序,能不能帮忙看一下有什么错啊该怎么处理
一个C++程序,能不能帮忙看一下有什么错啊?
请求用户输入10首歌名,保存在一个字符指针数组中,然后请按照用户输入的顺序、字母顺序和字母逆序分别显示这些歌名。
//C++ for the fifth time the first question in the homework
//According to certain requirements to save the title of songs the user's input in a character array
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
const numberOfSong=10;
int main ()
{
char *songName[numberOfSong],*name;
int i,j;
int longestNameLength; //longestNameLength is the longest song name's length
cout << "Please input the longest song name's length :\n"; //tell the user input the longestNameLength
cin >> longestNameLength;
cout << "Please input ten songs's names!\n"; //tell the user input the songs'names
//input the song'name
for ( i=0;i < numberOfSong;i++ )
{
for ( j=0;j < longestNameLength;j++ )
{
if ( *(songName[i]+j) != EOF )
cin >> *(songName[i]+j);
}
}
cout << "According to the order of user input output the songs'names :\n";
for ( i=0;i < numberOfSong;i++ )
{
for ( j=0;j < longestNameLength;j++ )
cout << *(songName[i]+j);
cout << "\n";
}
cout << "According to the alphabetical order output the songs'names :\n";
for ( i=0;i < numberOfSong;i++ )
{
if ( *songName[i] > *songName[i++] )
{
*name = *songName[i];
*songName[i] = *songName[i++];
*songName[i++] = *name;
}
else if ( *songName[i] == *songName[i++] )
{
for ( j=0;j < longestNameLength;j++ )
{
if ( *(songName[i]+j) > *(songName[i]+j+1) )
{
*name = *songName[i];
*songName[i] = *songName[i++];
*songName[i++] = *name;
}
}
}
}
for ( i=0;i < numberOfSong;i++ )
{
for ( j=0;j < longestNameLength;j++ )
cout << *(songName[i]+j);
cout << "\n";
}
cout << "According to the alphabetical reversed order output the songs'names :\n";
for ( i=0;i < numberOfSong;i++ )
{
if ( *songName[i] < *songName[i++] )
{
*name = *songName[i];
*songName[i] = *songName[i++];
*songName[i++] = *name;
}
else if ( *songName[i] == *songName[i++] )
{
for ( j=0;j < longestNameLength;j++ )
{
if ( *(songName[i]+j) < *(songName[i]+j+1) )
{
*name = *songName[i];
请求用户输入10首歌名,保存在一个字符指针数组中,然后请按照用户输入的顺序、字母顺序和字母逆序分别显示这些歌名。
//C++ for the fifth time the first question in the homework
//According to certain requirements to save the title of songs the user's input in a character array
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
const numberOfSong=10;
int main ()
{
char *songName[numberOfSong],*name;
int i,j;
int longestNameLength; //longestNameLength is the longest song name's length
cout << "Please input the longest song name's length :\n"; //tell the user input the longestNameLength
cin >> longestNameLength;
cout << "Please input ten songs's names!\n"; //tell the user input the songs'names
//input the song'name
for ( i=0;i < numberOfSong;i++ )
{
for ( j=0;j < longestNameLength;j++ )
{
if ( *(songName[i]+j) != EOF )
cin >> *(songName[i]+j);
}
}
cout << "According to the order of user input output the songs'names :\n";
for ( i=0;i < numberOfSong;i++ )
{
for ( j=0;j < longestNameLength;j++ )
cout << *(songName[i]+j);
cout << "\n";
}
cout << "According to the alphabetical order output the songs'names :\n";
for ( i=0;i < numberOfSong;i++ )
{
if ( *songName[i] > *songName[i++] )
{
*name = *songName[i];
*songName[i] = *songName[i++];
*songName[i++] = *name;
}
else if ( *songName[i] == *songName[i++] )
{
for ( j=0;j < longestNameLength;j++ )
{
if ( *(songName[i]+j) > *(songName[i]+j+1) )
{
*name = *songName[i];
*songName[i] = *songName[i++];
*songName[i++] = *name;
}
}
}
}
for ( i=0;i < numberOfSong;i++ )
{
for ( j=0;j < longestNameLength;j++ )
cout << *(songName[i]+j);
cout << "\n";
}
cout << "According to the alphabetical reversed order output the songs'names :\n";
for ( i=0;i < numberOfSong;i++ )
{
if ( *songName[i] < *songName[i++] )
{
*name = *songName[i];
*songName[i] = *songName[i++];
*songName[i++] = *name;
}
else if ( *songName[i] == *songName[i++] )
{
for ( j=0;j < longestNameLength;j++ )
{
if ( *(songName[i]+j) < *(songName[i]+j+1) )
{
*name = *songName[i];