当前位置: 代码迷 >> C语言 >> 求助~~大家帮一下忙吧~~看一下哪儿出错了
  详细解决方案

求助~~大家帮一下忙吧~~看一下哪儿出错了

热度:226   发布时间:2006-08-27 14:14:12.0
求助~~大家帮一下忙吧~~看一下哪儿出错了
#include"stdio.h"
void convert(long a,char p[])
{
int i,k,j,r,t[10];
while(a>0)
{
r=a%16;
if(r<10)t[i]=r+'0';
else t[i]=r-10+'A';
a=a/16;
i++;
}
for(k=i-1;k>=0;k--,j++)
p[j]=t[k];
}
main()
{
long a;
char b[10];
printf("please output a :");
scanf("%ld",&a);
if(a<=0)
{
printf("Error!!");
exit(0);
}
printf("please choose which you want:\n");
printf("1:10 convert 16:\n");
convert(a,b);
printf("the result is:");
puts(b);
}
请大家看看这个程序哪儿出问题了~~
谢谢了各位~
搜索更多相关的解决方案: convert  include  please  

----------------解决方案--------------------------------------------------------
#include"stdio.h"
#include "string.h"
void convert(long a,char p[])
{
int i=0,k,j,r;
char t[10];
while(a>0)
{
r=a%16;
if(r<10)t[i]=r+'0';
else t[i]=r-10+'A';
a=a/16;
i++;
}
t[i]='\0';
strcpy(p,strrev(t));
}
main()
{
long a;
char b[10];
printf("please output a :");
scanf("%ld",&a);
if(a<=0)
{
printf("Error!!");
exit(0);
}
printf("please choose which you want:\n");
printf("1:10 convert 16:\n");
convert(a,b);
printf("the result is:");
puts(b);
}

您的程序主要错误在int 和char型数组没定义好。其他都写得挺好
----------------解决方案--------------------------------------------------------

你的convert函数中的i=0;初始化了么?


----------------解决方案--------------------------------------------------------
字符串在默认的情况下是不需要加'\0'的
----------------解决方案--------------------------------------------------------

谢谢你们的帮助`我找到问题的所在了`
呵呵`~以后麻烦各位了`


----------------解决方案--------------------------------------------------------
  相关解决方案