有一个C程序需要大家的帮助,请指点
有一个C程序需要大家的帮助,请各位高手指点!
程序如下:
#if !defined(__STRNG_H )
#include<string.h>
#endif // __STRNG_H
#ifndef__IOSTREAM_H
#include<iostream.h>
#endif
//
// Determines themaximum string using the ASCII collating sequence to
// definerank. A string is defined to be greaterthan another if the
// ASCII values ofits characters are greater than the values of the other
// string. For example,
//
// strngmax AlphaBeta Charlie
//
// would printCharlie to stdout and return 3.
//
int main( intargc, char *argv[] )
{
if( argc < 2 )
{
cerr << "Usage: strngmax string1 [string2 ...]\n";
return 1;
}
char *theGreatestString( argv[1] );
int positionOfTheGreatestString = 1;
int nextArg = 2;
while( nextArg < argc )
{
char *argListString ( argv[nextArg++]);
if ( argListString >theGreatestString )
{
theGreatestString = argListString;
positionOfTheGreatestString = nextArg -1;
}
}
cout << theGreatestString << endl;
return positionOfTheGreatestString;
}
以上程序输入 strngmax 1234 3456 ,则可以得出结果3456
那么现在要修改成输入 strngmax 12345 67890 。则得到结果1234567890
请高手指教!
------解决方案--------------------
------解决方案--------------------
程序如下:
#if !defined(__STRNG_H )
#include<string.h>
#endif // __STRNG_H
#ifndef__IOSTREAM_H
#include<iostream.h>
#endif
//
// Determines themaximum string using the ASCII collating sequence to
// definerank. A string is defined to be greaterthan another if the
// ASCII values ofits characters are greater than the values of the other
// string. For example,
//
// strngmax AlphaBeta Charlie
//
// would printCharlie to stdout and return 3.
//
int main( intargc, char *argv[] )
{
if( argc < 2 )
{
cerr << "Usage: strngmax string1 [string2 ...]\n";
return 1;
}
char *theGreatestString( argv[1] );
int positionOfTheGreatestString = 1;
int nextArg = 2;
while( nextArg < argc )
{
char *argListString ( argv[nextArg++]);
if ( argListString >theGreatestString )
{
theGreatestString = argListString;
positionOfTheGreatestString = nextArg -1;
}
}
cout << theGreatestString << endl;
return positionOfTheGreatestString;
}
以上程序输入 strngmax 1234 3456 ,则可以得出结果3456
那么现在要修改成输入 strngmax 12345 67890 。则得到结果1234567890
请高手指教!
------解决方案--------------------
#include<string.h>
#include<iostream>
using namespace std;
int main( int argc, char *argv[] )
{
if( argc < 2 )
{
cerr << "Usage: strngmax string1 [string2 ...]\n";
return 1;
}
int nextArg = 1;
cout << "strngmax ";
while( nextArg < argc )
{
char *argListString ( argv[nextArg++]);
cout <<argListString;
}
}
------解决方案--------------------
int main( int argc, char *argv[] )
{
if( argc < 2 )
{