这个c程序哪里出错了

来源:百度知道 编辑:UC知道 时间:2024/05/22 13:54:26
#include <stdio.h>
#include<string.h>
void main ()
{ int i,j,t,m;
int a[100];
printf("请输入几个数:\n");
gets(a);
printf("\n");
m=strlen(a);
printf("原始数据是:\n");
for(i=0;i<m;i++)
printf("%d",a[i]);
for(i=1;1<m;i++)
{for(j=m-i;j>=0;j--)
if(a[j]>a[j-1])
{t=a[j-1];
a[j-1]=a[j];
a[j]=t;
}
}
printf("\n排列后的数据为:\n");
for(i=0;i<=m;i++)
printf("%d",a[i]);
}
wyj5.cpp
C:\Documents and Settings\Administrator\桌面\wyj5.cpp(7) : error C2664: 'gets' : cannot convert parameter 1 from 'int [100]' to 'char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
C:\Documents and Settings\Administrator\桌面\wyj5.cpp(9) : error C2664: 'strlen' : canno

cannot convert parameter 1 from 'int [100]' to 'char *'
不能将int[]强制转换成char*,应将a定义为char*

同时你的程序还应该完成以下几个功能:
1.非法字符输入判断
2.最好将字符转化为数字然后进行比较,虽然直接用字符比较也是没有问题。