传递“atoi”的参数 1;无需强制转换即可从整数生成指针......任何人都可以帮助我
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(){
int n;
int a,b,ans[10000];
char *c,*d,*e;
int i = 0;
c = (char*)(malloc(20 * sizeof(char)));
d = (char*)(malloc(20 * sizeof(char)));
scanf("%d",&n);
while(i < n){
scanf("%d",&a);
scanf("%d",&b);
itoa(a,c,10);
itoa(b,d,10);
a = atoi(strrev(c)) + atoi(strrev(d));
itoa(a,c,10);
e = c;
while(*e == '0')e++;
ans[i] = atoi(strrev(e));
i++;
}
i = 0;
while(i < n){
printf("%d\n",ans[i]);
i++;
}
}
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(){
int n;
int a,b,ans[10000];
char *c,*d,*e;
int i = 0;
c = (char*)(malloc(20 * sizeof(char)));
d = (char*)(malloc(20 * sizeof(char)));
scanf("%d",&n);
while(i < n){
scanf("%d",&a);
scanf("%d",&b);
itoa(a,c,10);
itoa(b,d,10);
a = atoi(strrev(c)) + atoi(strrev(d));
itoa(a,c,10);
e = c;
while(*e == '0')e++;
ans[i] = atoi(strrev(e));
i++;
}
i = 0;
while(i < n){
printf("%d\n",ans[i]);
i++;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的程序中没有声明
strrev
这样的函数。编译器假定它是某个返回int
的未知函数。因此,诊断消息是这样的,因为atoi
需要一个指针,而不是int
。什么是
strrev
?为什么你在不先声明的情况下尝试调用这个函数? C 标准库没有这样的函数,因此包含您已经包含的那些标准头文件是不够的(除非您假设一些扩展实现)。There's no such function as
strrev
declared in your program. The compiler assumes that it's some unknown function that returnsint
. Hence the diagnostic message, sinceatoi
expects a pointer, not anint
.What's
strrev
? And why are you attempting to call this function without declaring it first? C standard library has no such function, so including those standard headers that you have included already is not enough (unless you are assuming some extended implementation).除了
strrev
的问题不是标准的并且可以很容易实现,例如只是说(非就地恢复),您应该更喜欢使用
strtol
或 < code>strtoul 而不是atoi
并实现itoa
因为据我所知这也不是标准的(无论如何你都可以使用sprintf
如果基数为 10)。Apart the problem of
strrev
which is not standard and can be easily implemented e.g.just to say (not-in-place reversion), you should prefer the use of
strtol
orstrtoul
instead ofatoi
and implement alsoitoa
since afaik that is not standard too (you could usesprintf
anyway if the base is 10).