0
#include<stdio.h> 
#include<stdlib.h>
#include<string.h>
void main(void)
{
    int a,b,sub,i,count=0;char buffer[20],w[20];
    scanf("%d",&a);
    scanf("%d",&b);
    sub=a-b;
    if(sub>0)
    {
        scanf("%s",w); /*wrong answer*/
        itoa(sub,buffer,10);
        int l=strlen(buffer);
        for(i=0;i<l;i++)
        {
            if(w[i]==buffer[i])
                count++;
        }
        ((count==l || count==l-1) && w[0]!='0') ? printf("accepted") : printf("Not accepted");
    }
    else printf("Sub operation returned negative value");
}

The output of the compiler is

prog.c:4:6: warning: return type of 'main' is not 'int' [-Wmain]
 void main(void)
      ^
prog.c: In function 'main':
prog.c:13:1: warning: implicit declaration of function 'itoa' [-Wimplicit-function-declaration]
 itoa(sub,buffer,10);
 ^
/home/HCDVgj/ccHBnrc7.o: In function `main':
prog.c:(.text.startup+0x61): undefined reference to `itoa'
collect2: error: ld returned 1 exit status

I did not use any long int variables but i still get ld return 1 exists. how to debug these errors

CiaPan
  • 8,142
  • 2
  • 18
  • 32

2 Answers2

2
  • int main() This is teh first thing you should do.

  • scanf("%19s",w); This is better.

  • itoa is non standard (so you will not find it in any standard implementaion) better use snprintf()

  • printf('%s",((count==l || count==l-1) && w[0]!='0') ? "accepted" : "Not accepted"); More compact I would say.

Use of snprintf

snprintf(target, size_of_target1, "%d", source2);

sprintf takes no parameter specifying the number of bytes to write which may lead to buffer overflow which is not a good thing.

1 : In bytes
2 : source is in integer here

Few things worth mentioning to clear your idea or to be more precise

  • The output you specified is not output of the c program ... in the process of compilation your compiler run into error and then it generates those output. -CiaPan

  • main() shouldn't be of void return type it is expected to return 0 in case of normal termination. Abnormal termination is usually signaled by a non-zero.-David C. Rankin

user2736738
  • 28,590
  • 4
  • 37
  • 52
0

I don't know why you're talking about "long int variables".

The first warning can be fixed by changing void main(void) to int main(void) and adding a return 0; at the end.

The second warning tells you that the compiler doesn't know what itoa is.

The following linker error tells you that the linker (ld) also doesn't know what itoa is, and that's why compilation fails.

The reason itoa is unknown is that it's not a standard function and not available on your platform.

melpomene
  • 79,257
  • 6
  • 70
  • 127