calling function & called function

This is a discussion on calling function & called function within the C Programming forums, part of the General Programming Boards category; Can anyone tell me what is the error in program mentioned below. It shows syntax error : missing ';' before ...

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    4

    Exclamation calling function & called function

    Can anyone tell me what is the error in program mentioned below. It shows syntax error : missing ';' before '{'. I am using visual studio compiler.
    #include<stdio.h>
    void main()

    {
    cts();

    cts()
    {
    printf(" hi ");

    }
    }


  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Uh, where to begin.

    First of all, main() should return an int, and probably receive void:

    Code:
    int main(void)
    Secondly, you are defining a function cts() inside of main(). You aren't supposed to do that. You might want something like this as your function definition:

    Code:
    void cts(void)
    {
        printf(" hi ");
    }

  3. #3
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by Sajal View Post
    Can anyone tell me what is the error in program mentioned below. It shows syntax error : missing ';' before '{'. I am using visual studio compiler.
    #include<stdio.h>
    void main()

    {
    cts();

    cts()
    {
    printf(" hi ");

    }
    }
    In C any function can not be defined inside any other function's definition. But it can be declared inside other function.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  4. #4
    Registered User
    Join Date
    Jun 2009
    Posts
    452
    On top of all that, you forgot the semicolon after the second cts(), hence the error you get.

  5. #5
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by KBriggs View Post
    On top of all that, you forgot the semicolon after the second cts(), hence the error you get.
    Second cts() starts the definition of the function and thus no need to put a semicolon. Function definitions dont have an ending semicolon but declarations have.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 28
    Last Post: 07-17-2006, 12:35 AM
  2. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 11:03 AM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. Function calling woes
    By RedZippo in forum C Programming
    Replies: 6
    Last Post: 01-09-2004, 12:39 AM
  5. Question on function syntax and calling function
    By cbrman in forum C Programming
    Replies: 10
    Last Post: 10-05-2003, 06:32 PM

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