ERROR: undefined reference to 'counter'

This is a discussion on ERROR: undefined reference to 'counter' within the C Programming forums, part of the General Programming Boards category; it return an error as topic!! yet this code is not complete. Code: #include <stdio.h> int counter(int num); int x,digits; ...

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    12

    ERROR: undefined reference to 'counter'

    it return an error as topic!!
    yet this code is not complete.
    Code:
    #include <stdio.h>
    int counter(int num);
    int x,digits;
    
    main()
    {
        int i;
            for(i=1;;i++)
                {
                    scanf("%d",&x);
                    digits = counter(x);
                     //   if(digits==5)
                      //      break;
                        //else
                          //  printf("enter 5 digits number!\n");
                            //continue;
                            printf("%d",digits);
                }
    
       int counter(int num)
            {
                int i,a=0;
                for(i=1;num>0;i++){
                    num/=10;
                    return i;
            }
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,313
    Indent your code properly. You will find that counter is defined local to main (which is not standard C, I believe). Define it after defining the main function.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Feb 2012
    Posts
    12
    counter is a function which its prototype is b4 main!!! it should works any way ):

  4. #4
    Registered User
    Join Date
    Feb 2012
    Posts
    12
    i got it..yeah i should wrote my code better... tnx

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linker Error - Undefined Reference
    By DaNxTh3xMaNx in forum C Programming
    Replies: 3
    Last Post: 09-07-2011, 06:49 PM
  2. gcc error, undefined reference
    By drshmoo in forum C Programming
    Replies: 2
    Last Post: 04-04-2011, 10:33 PM
  3. Undefined reference error
    By pshirishreddy in forum C Programming
    Replies: 11
    Last Post: 08-02-2009, 07:34 PM
  4. Undefined Reference Error
    By NuNn in forum C Programming
    Replies: 12
    Last Post: 01-15-2009, 01:34 PM
  5. undefined reference error
    By gcctest in forum C Programming
    Replies: 3
    Last Post: 12-19-2008, 08:17 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21