Thread: urgent help needed with itoa

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #20
    Registered User
    Join Date
    Nov 2008
    Posts
    222
    If I test below code, it throws errors. I am not sure why these errors are coming here?
    Where are these multiple definitions for itoa, main and reverse?

    Code:
    #include <stdio.h>
    #include <stdbool.h>
     
    void reverse(char output[], int len)
    {
       int start, end;
       char temp;
       for(start=0, end=len-1; start < end; start++, end--) {
          temp = *(output+start);
          *(output+start) = *(output+end);
          *(output+end) = temp;
       }
    }
     
    void itoa (int input, char* output, int rad){
       int i = 0;
       bool isnegative = false;
     
       if(input == 0) {
          output[i] = '0';
          output[i + 1] = '\0';
       }
     
       if(input < 0 && rad == 10){
          isnegative = true; // NOT bool isnegative = true;
          input = -input;
       }
     
       while (input != 0){
          int rem = input%rad;
          output[i++] = (rem > 9) ? (rem-10) + 'A' : rem + '0';
          input = input/rad;
       }
     
       if(isnegative){
          output[i++] = '-';
       }
     
       output[i] = '\0';
       reverse(output, i);
    }
     
     
    int main (){
     
       int i, b;
       char array[148];
       printf("Enter a number and base\n");
       scanf("%d %d", &i, &b);
     
       itoa(i, array, b);
       printf("String : %s\n", array);
     
       return 0;
    }
    
    OUTPUT: 
    main.c:(.text+0x0): multiple definition of `reverse'; /tmp/ccPlW4oc.o:main.c:(.text+0x0): first defined here
    /usr/bin/ld: /tmp/ccAtpqk9.o: in function `itoa':
    main.c:(.text+0x7a): multiple definition of `itoa'; /tmp/ccPlW4oc.o:main.c:(.text+0x7a): first defined here
    /usr/bin/ld: /tmp/ccAtpqk9.o: in function `main':
    main.c:(.text+0x160)  : multiple definition of `main'; /tmp/ccPlW4oc.o:main.c:(.text+0x160): first defined here
    collect2: error: ld returned 1 exit status
    Last edited by leo2008; 10-11-2021 at 07:40 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Urgent, help needed.
    By sinnclaus in forum C Programming
    Replies: 4
    Last Post: 03-29-2010, 06:08 AM
  2. Urgent Help needed!
    By Superstar90 in forum C++ Programming
    Replies: 3
    Last Post: 11-10-2009, 04:21 PM
  3. urgent help needed!!!
    By yosef_yaniv in forum C++ Programming
    Replies: 5
    Last Post: 12-08-2007, 12:36 PM
  4. Urgent! Help Needed
    By DarkManiac in forum C++ Programming
    Replies: 4
    Last Post: 04-14-2004, 07:16 PM
  5. urgent help needed
    By david in forum C Programming
    Replies: 0
    Last Post: 11-27-2001, 08:27 AM

Tags for this Thread