第1个回答 2011-04-09
#include<string.h>
void convert(char *a,char *b,char *c);
void main()
{
int i,j;
char a[3][10];
for(i=0;i<3;i++)
{
printf("input the %d string:\n",i+1);
scanf("%s",a[i]);//指针的用法注意点
}
convert(a[0],a[1],a[2]);
printf("after change\n");
for(j=0;j<3;j++)
{
printf("%s ",a[j]);//注意i,j啊,这个错误太隐蔽了
}
}
void convert(char *a,char *b,char *c)
{
char temp[10];
if(strcmp(a,b)>0)
{
strcpy(temp,a);
strcpy(a,b);
strcpy(b,temp);
}
if(strcmp(a,c)>0)
{
strcpy(temp,a);
strcpy(a,c);
strcpy(c,temp);
}
if(strcmp(b,c)>0)
{
strcpy(temp,b);
strcpy(b,c);
strcpy(c,temp);
}
}
第2个回答 2011-04-08
假设操作文档为d:\1.txt
输出文件为d:\temp.txt
Dim a()
Private Sub Command1_Click()
Open "d:\1.txt" For Input As #1
Do Until EOF(1)
z = z + 1
ReDim Preserve a(z)
Line Input #1, w
a(z) = Len(w) & "*" & w
Loop
Close
For i = 1 To z - 1
For j = i + 1 To z
t = Split(a(i), "*")
q = Split(a(j), "*")
If Val(t(0)) < Val(q(0)) Then
temp = a(i)
a(i) = a(j)
a(j) = temp
End If
Next j
Next i
Open "d:\temp.txt" For Output As #2
For i = 1 To z
y = Split(a(i), "*")
Print #2, y(1)
Next i
Close
End Sub