tags:

views:

69

answers:

2
#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++;
            }
}
+2  A: 

There'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).

AndreyT
It's apparently declared in string.h: http://linux.die.net/man/3/strrev
Fred Larson
It is given as a library function athttp://www.warpspeed.com.au/cgi-bin/inf2html.cmd?..%5Chtml%5Cbook%5CToolkt40%5CXPG4REF.INF+275
somasekhar
It's not in MY string.h, though - gcc 4.4.1 on Ubuntu. @somasekhar, what's your environment?
Fred Larson
`strrev` is not a standard C function, so there's nothing surprising in in not being declared in a general case.
AndreyT
Thank You .I am using dev cpp on windows.This code is to be submitted on www.codechef.com,a practice problem.It do not have an option of dev c++.So,I have selected as gcc 4.3.2. But,it is working on dev cpp.SO I think gcc 4.3.2 do not have the function strrev().
somasekhar
Regarding strrev(). POSIXv6/SUSv3 doesn't have a mention of it. Neither C99 (N1124). Linux and FreeBSD do not have a man page for it. Conclusion: function isn't standard.
Dummy00001
A: 

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).

ShinTakezou