#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++;
}
}
views:
69answers:
2There's no such function as strrev declared in your program. The compiler assumes that it's some unknown function that returns int. Hence the diagnostic message, since atoi expects a pointer, not an int.
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).
Apart the problem of strrev which is not standard and can be easily implemented e.g.
char *strrev(char *s)
{
size_t l = strlen(s), i;
char *r = malloc(l + 1);
if ( r != NULL ) {
for(s += l-1, i=0; i < l; i++, s--) r[i] = *s;
r[i] = '\0';
}
return r;
}
just to say (not-in-place reversion), you should prefer the use of strtol or strtoul instead of atoi and implement also itoa since afaik that is not standard too (you could use sprintf anyway if the base is 10).