/*排序字符串,若输入: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<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;//替换
}
}
}
}
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;
另外,虚机团上产品团购,超级便宜