C语言改错 改FOUND 下面的

/*排序字符串,若输入:this test terminal,以下程序的输出结果为:terminal test this.*/
#include<stdio.h>
#include<string.h>

#define MAXLINE 20

void sort(char *pstr[]);

int main(void)
{
int i;
char *pstr[3], str[3][MAXLINE];

for (i=0; i<3; i++)
{
pstr[i] = str[i];
}

printf("Please input:");
for (i=0; i<3; i++)
{
/*********Found************/
scanf("%s ", pstr+i);
}

sort(pstr);
printf("output:");
for (i=0; i<3; i++)
{
/*********Found************/
printf("%s\n", pstr+i);
}

return 0;
}

void sort(char *pstr[])
{
int i, j;
char *p;

for (i=0; i<3; i++)
{
for (j=i+1; j<3; j++)
{
/*********Found************/
if (strcmp(*(pstr+i), *(pstr+j)) > 0)
{
p = *(pstr+i);
*(pstr+i) = *(pstr+j);
*(pstr+j) = p;
}
}
}
}

#include<stdio.h>
#include<string.h>

#define MAXLINE 20

void sort(char *pstr[]);

int main(void)
{
int i;
char *pstr[3], str[3][MAXLINE];

for (i=0; i<3; i++)
{
pstr[i] = str[i];
}

printf("Please input:");
for (i=0; i<3; i++)
{
/*********Found************/
scanf("%s", *(pstr+i));//s后面的空格要删除
}

sort(pstr);
printf("output:");
for (i=0; i<3; i++)
{
/*********Found************/
printf("%s\n", pstr[i]);
}

return 0;
}

void sort(char *pstr[])
{
int i, j;
char *p;

for (i=0; i<3; i++)
{
for (j=i+1; j<3; j++)
{
/*********Found************/
if (strcmp(*(pstr+i), *(pstr+j)) > 0)//这里没有错
{
p = *(pstr+i);//储存地址
*(pstr+i) = *(pstr+j);//替换
*(pstr+j) = p;//替换
}
}
}
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-04-20
********FOUND**********/
b=a;
/**********FOUND**********/
a=t;

改为:
t=a;
/**********FOUND**********/
//b=a;
a=b;
/**********FOUND**********/
//a=t;
b=t;

r=a/b;改为r=a%b;
return a; 改为 return b;
另外,虚机团上产品团购,超级便宜

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网