有一个C程序需要大家的帮助,请各位高手指点!

Falleyes 2012-12-24 09:25:41
程序如下:
#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

请高手指教!
...全文
230 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2012-12-25
  • 打赏
  • 举报
回复
引用 4 楼 turingo 的回复:
C/C++ code?1234567891011121314151617#include <stdio.h> int main(int argc, char* argv[]){ int i; if(argc < 2){ printf("string1 [string2 ...]\n"); return 1; } for(i = 1; i < arg……
#include <stdio.h>

int main(int argc, char* argv[])
{
  int i;

  if(argc < 2){
    printf("%s string1 [string2 ...]\n",argv[0]);
    return 1;
  }

  printf("%s ", argv[0]);
  for(i = 1; i < argc; i++)
    printf("%s", argv[i]);
  printf("\n");
 
  return 0;
}
图灵狗 2012-12-24
  • 打赏
  • 举报
回复

#include <stdio.h>

int main(int argc, char* argv[])
{
  int i;

  if(argc < 2){
    printf("string1 [string2 ...]\n");
    return 1;
  }

  for(i = 1; i < argc; i++)
    printf("%s", argv[i]);
  printf("\n");

  return 0;
}
sxldfang 2012-12-24
  • 打赏
  • 举报
回复
int main( int argc, char *argv[] )
{
    if( argc < 2 )
    {
        cout << "Usage:  strngmax string1 [string2 ...]\n";
        return 1;
    }
    while(*++argv!=NULL)cout<<argv[0];

    return 0;
}
欢乐的小熊 2012-12-24
  • 打赏
  • 举报
回复
#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;
	}
}
phpman_cn 2012-12-24
  • 打赏
  • 举报
回复
将第一和第二个参数合并输出就可以了.
Falleyes 2012-12-24
  • 打赏
  • 举报
回复
上面有给出答案的,但是没有吧后面的字符串连接起来 输出是 strngmax 12345 67890 并不是我要的 strngmax 1234567890 希望能做下修改!

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧