-4

I keep getting a strange syntax error that i've never seen before, and I'm not sure what's the problem with it. Can I get some extra eyes to help me figure out what the problem is?

the error reads: error: expected declaration or statement at end of input the bold line is what it highlights as the error.

void draw(int deck[SIZE])
{
     int i; 

     for(i = 0; i < 5; i++)
     {
           cards;
           putchar('\n');
           }

void cards()
{
         char suits[4][9] = 
    {
        "Hearts",
        "Diamonds",
        "Clubs",
        "Spades"};

         for(i=0; i<SIZE; i++)
    {       
        if(i%13 == 0 || i%13 == 10 || i%13 == 11 || i%13 == 12)
            printf("%s ", facecheck(i%13) );
        else printf("%d ", i%13+1);
        printf("of %s \n", suits[i/13]);
    };

**}**
Jim Balter
  • 16,163
  • 3
  • 43
  • 66
Rini Posny
  • 343
  • 1
  • 4
  • 5

3 Answers3

4

You didn't close draw function. You're missing a } at the end:

void draw(int deck[SIZE])
{
     int i; 
     for(i = 0; i < 5; i++)
     {
           cards;
           putchar('\n');
     }
} //ADD ME PLEASE :(

As stated on the comments, a good IDE could have caught this before compiling.

I also recommend you to indent your code so you can better match opening/closing braces.

Your code suffers from additional errors, I highly recommend you to read a tutorial and to review your code.

Maroun
  • 94,125
  • 30
  • 188
  • 241
  • 1
    Also worth noting, a good IDE (even Notepad++, to some extent) will catch this before you compile. – jedwards Apr 05 '13 at 22:28
1

'cards;' looks suspect as it's the name of a function

dan
  • 982
  • 8
  • 24
  • True, it's a logic error, but I don't think that's a compiler error. http://liveworkspace.org/code/2dp6eB%241 – chris Apr 05 '13 at 22:27
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. – eugen Apr 05 '13 at 22:49
  • @chris No, it's a syntax error, not a logic error ... C doesn't allow nested functions. Your snippet isn't relevant. – Jim Balter Apr 05 '13 at 23:10
  • @eugen danf doesn't have enough rep to leave comments. It's one of those SO policies that makes little sense, because it just encourages beginners to post their comments as answers. – Jim Balter Apr 05 '13 at 23:12
  • @JimBalter, The definition of `cards` would be, yes, but `cards;` itself, provided there's a forward declaration, should not. It just needlessly evaluates it. – chris Apr 05 '13 at 23:13
  • @chris Sorry, I thought danf was referring to the major error (the definition of `cards` occurring within the scope of `draw`). I should have paid more attention. "It just needlessly evaluates it." -- well, it declares it; it doesn't evaluate anything -- but it presumably should. But then a declaration *is* needed. – Jim Balter Apr 05 '13 at 23:15
0
        for(i=0; i<SIZE; i++)
        {       
           if(i%13 == 0 || i%13 == 10 || i%13 == 11 || i%13 == 12)
           printf("%s ", facecheck(i%13) );
           else printf("%d ", i%13+1);
           printf("of %s \n", suits[i/13]);
        }; //no need of semi-colon after curly brace
    }
 } //missing curly brace
A human being
  • 1,220
  • 8
  • 18
  • Whoever has given me -1 on this answer, please tell me where I'm wrong, so that I won't repeat it in future. Thanks. – A human being Apr 05 '13 at 22:37
  • I didn't downvote you, but it completely misses the real problem ... that's the wrong place for the missing curly. Also, your edit of the OP's question makes it much worse. – Jim Balter Apr 05 '13 at 23:06
  • I'm not saying that you downvoted me, I just asked about my mistake.Why it's the wrong place for missing curly brace?It could be possible that cards is defined inside draw, ain't it? – A human being Apr 05 '13 at 23:15
  • "I'm not saying that you downvoted me" -- And I didn't say you said that, I simply noted that I'm not that person. "I just asked about my mistake" -- you asked it of the person who downvoted you. If I hadn't said I did not, it would have been reasonable to assume that I did. "It could be possible" -- No, that's not legal C; did you try it? – Jim Balter Apr 05 '13 at 23:18
  • 1
    "it works in gcc" -- if your flags allow extensions. However, this is not tagged [gcc]. "not sure" -- No, it definitely is not legal C. "Yep" -- If you're going to answer questions tagged [c] at SO, you need to become more familiar with the language so that your answers don't reflect gcc idiosyncrasies ... possibly with the help of flags like -ansi -pedantic – Jim Balter Apr 05 '13 at 23:22
  • 1
    You're welcome. Here's more: http://stackoverflow.com/questions/2608158/nested-function-in-c – Jim Balter Apr 05 '13 at 23:33