Thread: Declaration of own function

  1. #1
    Registered User
    Join Date
    Jan 2012
    Posts
    3

    Declaration of own function

    I receive warrning: Implict declaration of function
    How can I resolve this warrning?

    p.s. my function is transp()

    Code:
    #include <stdio.h>
    
    int main()
    
    {
    
    
        printf("Iveskite bet koki sveikaji skaiciu intervale nuo 0 iki 999999999.\n");
        printf("\n");
        transp(); /* mano funkcija*/
        return 0;
    }
    
    /*Mano funkcija transp()*/
    #include <stdio.h>
    
    int transp()
       {
        int a,b,c,i,j,l,m,x,keiti;
        int me=-1,mdy=-1,z=8,sum=0;
        int mas[z], masx[z];
        scanf("%10d", &a);
        printf("\n");
        printf("%d - Jusu ivestas skaicius. \n", a);
        for(b=a; b%100000000!=0; b/=10) /*ciklas nustatantis skaiciaus elementu skaiciu,
                                          masyvo dydi, bei sukeliantis skaiciaus elementus i masyva*/
            {
             mdy++;
             me++;
             c=b%10;
             mas[me]=c;
            }
        printf("\n");
        if(me+1>9) /*nustato ar ivestas ne per didelis skaicius*/
            {
             printf("Jus ivedete per dideli skaiciu.\n");
             return 0;
            }
        else
        printf("Skaicius susideda is %d skaitmenu.\n", me+1);
        printf("\n");
        l=1;
        do
            {
             for(i=0; i<mdy; i++) /*masyvo elementu rikiavimas pagal uzduoti*/
             if(mas[i]<mas[i+1])
                {
                 keiti=mas[i];
                 mas[i]=mas[i+1];
                 mas[i+1]=keiti;
                }
             l++;
            }
        while(l!=10); /*operacija kartojama kad tikrai visi skaiciai susirikiuotu taip kaip reikia*/
        printf("Pagal uzduoti pertvarkytas skaicius yra: \n");
        printf("\n");
        x=0;
        z=mdy;
        for(j=1; j<=1000000000; j*=10) /*surikiuoto masyvo elementu pavertimas 1 skaiciumi*/
            {
             if(x>mdy)
             break;
             m=1*j;
             masx[z]=m;
             z--;
             x++;
            }
        for(i=0; i<=me; i++)
        sum=sum+(mas[i]*masx[i]);
        printf("%d \n", sum);
        return 0;
       }

  2. #2
    Registered User joybanerjee39's Avatar
    Join Date
    Oct 2011
    Location
    kolkata
    Posts
    106
    you have to use
    Code:
    #include<stdio.h>
    only before main.
    you have to give the prototype of
    Code:
    int transp()
    before using it in main.

  3. #3
    Registered User
    Join Date
    Jan 2012
    Posts
    3
    Quote Originally Posted by joybanerjee39 View Post
    you have to use
    Code:
    #include<stdio.h>
    only before main.
    you have to give the prototype of
    Code:
    int transp()
    before using it in main.
    How can I do it?

  4. #4
    Registered User
    Join Date
    Oct 2011
    Location
    Denmark
    Posts
    80
    HomePort : A C Web Service API for heterogeneous home automation systems

  5. #5
    Registered User
    Join Date
    Jan 2012
    Posts
    11
    Quote Originally Posted by Minderis View Post
    How can I do it?
    You include the library only once before main function and add prototype before using it in main.
    Example:
    Code:
    //Include the library
    #include <stdio.h>
    //prototype of function
    int transp();
    //main function
    int main()
    {
    .......
    //Call functions
    ......
    return 0;
    }
    //Write body of function here.
    int transp()
    {
    ......
    }
    Sorry my english is very bad!.

  6. #6
    Registered User joybanerjee39's Avatar
    Join Date
    Oct 2011
    Location
    kolkata
    Posts
    106
    Quote Originally Posted by cauberong09 View Post
    You include the library only once before main function and add prototype before using it in main.
    Example:
    Code:
    //Include the library
    #include <stdio.h>
    //prototype of function
    int transp();
    //main function
    int main()
    {
    .......
    //Call functions
    ......
    return 0;
    }
    //Write body of function here.
    int transp()
    {
    ......
    }
    Sorry my english is very bad!.
    don't do that.
    let him research a bit and actually learn.

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Alternatively you can just move the text of the function above main in your source code.

    C reads "top down" and doesn't know about anything it hasn't seen yet... so if you want it to find stuff you have to either prototype it or declare it before it's called.

  8. #8
    Registered User
    Join Date
    Jan 2012
    Posts
    3
    Thanks for answers.
    to: joybanerjee3
    Yes, I was read your links, and find how to declarate function it was exactly like cauberong09 wrote.

  9. #9
    Registered User
    Join Date
    Jan 2012
    Posts
    11
    Quote Originally Posted by joybanerjee39 View Post
    don't do that.
    let him research a bit and actually learn.
    Oh,I am sorry,I will notice after.Thanks you.

  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Minderis
    Yes, I was read your links, and find how to declarate function it was exactly like cauberong09 wrote.
    Then the articles that you read were either for C++ rather than C, or were not thorough. This:
    Code:
    int transp();
    declares a function named transp that has an unknown number of parameters and returns an int. This:
    Code:
    int transp(void);
    declares a function named transp that has no parameters and returns an int.

    You don't need to specify void in the function definition to specify that it has no parameters, but in a function declaration it matters.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. declaration of a function
    By kaal in forum C++ Programming
    Replies: 1
    Last Post: 02-06-2011, 10:37 PM
  2. function declaration in Main function
    By filipn in forum C Programming
    Replies: 2
    Last Post: 11-11-2009, 01:31 PM
  3. Function declaration
    By Jef Patat in forum C Programming
    Replies: 9
    Last Post: 09-13-2008, 02:39 PM
  4. Function Declaration
    By leeor_net in forum C++ Programming
    Replies: 5
    Last Post: 09-05-2007, 12:32 PM
  5. C++ function declaration
    By gustavosserra in forum C++ Programming
    Replies: 2
    Last Post: 09-07-2003, 11:15 AM