ALignment C program compiling issue

0 votes
asked Jul 18, 2018 by xon
Every time i try to compile this c program i get this error: cannot convert ‘double*’ to ‘const char*’ for argument ‘1’ to ‘int atoi(const char*)’ and when i try online gdb it works perfectly fine.Here is the code can anyone point out me to my mistake why this code not compiling on my side?

CODE:

#include <stdio.h>
#include <stdlib.h>

struct {
    char c;
    double d;
} s;

int main(int argc,char *argv[])
{
     int a;

     a = atoi(&s.d) - atoi(&s.c);
     printf("alignment=%d\n",a);
     printf("Size of char: %d\n",sizeof(s.c));
     printf("Size of double: %d\n",sizeof(s.d));
     printf("Size of struct: %d\n",sizeof(s));
}

1 Answer

0 votes
answered Jul 20, 2018 by KAUSTAV (720 points)
Friend, I used codeblocks 17.12 compiler and it's working fine. Though atoi is not a compiler dependent function, still, you can make your own atoi function using the below link (My guess is if you are using an old compiler like turbo c++ then it might not contain atoi) :-

https://www.geeksforgeeks.org/write-your-own-atoi/
commented Jul 20, 2018 by 0xlearner (100 points)
I am running this on Debian gcc (Debian 7.3.0-25) 7.3.0 and i guess it is the up to date compiler then i why it is not working,it's working just fine on gdb online as well.
I am usning sublime text.
commented Jul 21, 2018 by KAUSTAV (720 points)
See, I think Debian gcc doesn't support atoi function. Please search on it, especially post it as bug in their official blog-site. And, if possible try using " itoa " instead of  " atoi ".
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...