This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

TOGGLE.C(10): error C141: syntax error near '}'

i am facing error C141: syntax error near '}'

my program is given below:

#include<reg51.h>
void main ( )
{ int x; while (1) { P1 = 0x00 ; for (x=0 ; x<=5000 ; x++) P1 = 0xFF ; for (x=0 ; x<=5000 ; x++) } }

any one can help me how to solve it

Parents
  • In this case, we would have liked to see if the OP wrote code looking like (not too likely, since it gives a silly result):

    void main ( )
    {
            int x;
            while (1)
            {
                    P1 = 0x00 ;
                    for (x=0 ; x<=5000 ; x++)
                            P1 = 0xFF ;
                    for (x=0 ; x<=5000 ; x++)
             }
    }
    

    Or (still same silly result):

    void main ( )
    {
            int x;
            while (1)
            {
                    P1 = 0x00 ;
                    for (x=0 ; x<=5000 ; x++) P1 = 0xFF ;
                    for (x=0 ; x<=5000 ; x++)
             }
    }
    

    or (showing misunderstanding of what ends a for() statement - or a copy/paste error):

    void main ( )
    {
            int x;
            while (1)
            {
                    P1 = 0x00 ;
                    for (x=0 ; x<=5000 ; x++)
                    P1 = 0xFF ;
                    for (x=0 ; x<=5000 ; x++)
             }
    }
    

    The missing semicolon on the second for() loop indicates that the OP might have written the code as in the third example. So assuming the for() loop could handle itself, and that the P1 = 0xFF assignment would happen after the loop was done.

    Or maybe the OP did write code like:

    void main ( )
    {
            int x;
            while (1)
            {
                    P1 = 0x00 ;
                    P1 = 0xFF ;
             }
    }
    


    And then added the for() loops when noticing that the assigns directly after each other was too fast. And then did a copy/paste of a line with a missing ';' and couldn't understand why the first for() wasn't flagged as broken but the second was.

    In the end - this is a specific case where the indentation would have told us more - even if we are able to read the one-liner.

Reply
  • In this case, we would have liked to see if the OP wrote code looking like (not too likely, since it gives a silly result):

    void main ( )
    {
            int x;
            while (1)
            {
                    P1 = 0x00 ;
                    for (x=0 ; x<=5000 ; x++)
                            P1 = 0xFF ;
                    for (x=0 ; x<=5000 ; x++)
             }
    }
    

    Or (still same silly result):

    void main ( )
    {
            int x;
            while (1)
            {
                    P1 = 0x00 ;
                    for (x=0 ; x<=5000 ; x++) P1 = 0xFF ;
                    for (x=0 ; x<=5000 ; x++)
             }
    }
    

    or (showing misunderstanding of what ends a for() statement - or a copy/paste error):

    void main ( )
    {
            int x;
            while (1)
            {
                    P1 = 0x00 ;
                    for (x=0 ; x<=5000 ; x++)
                    P1 = 0xFF ;
                    for (x=0 ; x<=5000 ; x++)
             }
    }
    

    The missing semicolon on the second for() loop indicates that the OP might have written the code as in the third example. So assuming the for() loop could handle itself, and that the P1 = 0xFF assignment would happen after the loop was done.

    Or maybe the OP did write code like:

    void main ( )
    {
            int x;
            while (1)
            {
                    P1 = 0x00 ;
                    P1 = 0xFF ;
             }
    }
    


    And then added the for() loops when noticing that the assigns directly after each other was too fast. And then did a copy/paste of a line with a missing ';' and couldn't understand why the first for() wasn't flagged as broken but the second was.

    In the end - this is a specific case where the indentation would have told us more - even if we are able to read the one-liner.

Children
No data