Thread: An error again in my own function

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    99

    An error again in my own function

    I have this source code:
    Code:
    #include <stdio.h>
    
    void cool()
    
    int main()
    {
    printf("NJHGJG GFS COL\n");
    cool()
    printf("asfasf as f as a!\n");
    cool()
    printf("adasfasf fg 45\n");
    printf("ashdjas ashfas\n");
    }
    void cool()
    {
    printf(" Poor kitty\n");
    }
    and when i try compile i get this:
    "dokimi9.c", line 6: warning: a function is declared as an argument
    "dokimi9.c", line 6: syntax error at or near symbol {
    any suggesions, do you see any wrong at the codE?

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    When calling a function, as with any statement, end in a ; as seen here:
    Code:
    #include <stdio.h>
    
    void foo( void );
    
    int main( void )
    {
        foo( );
    
        return 0;
    }
    
    void foo( void )
    {
        printf("Like so...\n");
    }
    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Apr 2004
    Posts
    21
    void cool()

    Should be :

    void cool();

    Your actual calls to cool() need a semi colon aswell like :

    cool();

    Stan

  4. #4
    Registered User
    Join Date
    Jul 2004
    Posts
    99
    Yes soory!
    The tutorila i have sucks, it doesn have the ;
    any good tutor maybe?

  5. #5
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    Quote Originally Posted by cogeek
    Yes soory!
    The tutorila i have sucks, it doesn have the ;
    any good tutor maybe?


    Here man, try this one out first. I'd also recommend a good book on C as well. Search the board or google for it.
    Warning: Opinions subject to change without notice

    The C Library Reference Guide
    Understand the fundamentals
    Then have some more fun

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    A tutorial which uses gets() in an example, without plenty of warnings - tut tut

    The array stuff could be better as well.

    [edit]
    Also, the author doesn't know why the malloc examples needed a cast (it doesn't in C).
    The answer, should anyone be interested is because they were compiling their 'C' code with a 'C++' compiler.
    [/edit]
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    Quote Originally Posted by Salem
    A tutorial which uses gets() in an example, without plenty of warnings - tut tut

    The array stuff could be better as well.
    I actually haven't checked it out. I'm doing mine by a book, not bad. ummmm....I think this one might be better for him. the only problem is it might be a little advance.

    The thing to remember cogeek is - if you don't have a good book on C - try the tutorials and come on the board often and show your code and let others critique it. you'll learn a whole lot. Actually even if you do have a "good" book, come on the board regulary. You'd be amazed at some of the crap out there passing for good C programming. I've learned a lot on this board and I'm sure you will too.
    Worse case scenarion pm Salem with your programming problems. He loves that.

    [edit]while we are on this subject Salem, Why doesn't the board have a decent tutorial on C? so many ppl could use it. Why don't you and prelude get togather and do one. I'd even pay to get it [/edit]
    Last edited by caroundw5h; 07-27-2004 at 10:29 AM. Reason: question:
    Warning: Opinions subject to change without notice

    The C Library Reference Guide
    Understand the fundamentals
    Then have some more fun

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Yes, that link is much better.

    You can also use this one, which is by the same author of the comp.lang.c FAQ (which is required reading IMO once you're up and running)

    > Worse case scenarion pm Salem with your programming problems. He loves that.
    Bad idea - you'll find yourself being ignored if you do.

    > while we are on this subject Salem, Why doesn't the board have a decent tutorial on C?
    It could certainly do with links to known good tutorial sites.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    Registered User caroundw5h's Avatar
    Join Date
    Oct 2003
    Posts
    751
    Quote Originally Posted by Salem
    > while we are on this subject Salem, Why doesn't the board have a decent tutorial on C?
    It could certainly do with links to known good tutorial sites.
    Maybe the webmaster or moderator should get some togather. I have a couple of them. And It'd be great if one could be done by the memebers of the board. I guess i need to get in touch with Hammer?

    [edit]I just notice too the c++ tutorials could do with a bit of updating. <iostream.h> ?? [/edit]
    Last edited by caroundw5h; 07-27-2004 at 01:47 PM.
    Warning: Opinions subject to change without notice

    The C Library Reference Guide
    Understand the fundamentals
    Then have some more fun

  10. #10
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>Maybe the webmaster or moderator should get some togather.
    http://faq.cprogramming.com/cgi-bin/...&id=1031248558
    http://faq.cprogramming.com/cgi-bin/...&id=1031248558

    If you know of any you want adding, let me know (via PM).
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM