Why can't I get this to compile

Blake KochBlake Koch Posts: 39
edited 2020-09-03 - 17:10:21 in Propeller 1
I can't seem to get this to compile, can someone point out why the compiler keeps telling me "var (i) is undeclared"?



#include "simpletools.h" // Include simple tools
char text[16];
char pass[7] = {"abc 123"};

int main() // Main function
{
__print("Enter Password: ");
__for(int i = 0; i < 16; ++i );
__{
_____text = getChar();
_____putChar('*')
_____if(text == '\r' || text == '\n')
_____{
_________putChar('\n');
_________text = 0;
_________break;
_____}
__}

__if(!strcmp(pass, text))
__{
_________print("(pass does match text)\n");
__}
__else
__{
_________print("(pass word does NOT match text)\n");
__}

}


SimpleIDE Version 1.1.2
C:/Users/SimpleIDE/ Updated on: 2020-08-31


Password Check.c: In function 'main':
Password Check.c:13:14: error: 'i' undeclared (first use in this function)
Password Check.c:13:14: note: each undeclared identifier is reported only once for each function it appears in
Password Check.c:15:9: error: expected ';' before 'if'
Done. Build Failed!

Click error or warning messages above to debug.
the ____ are just Blank spaces to show the indent.
Thanks.

Comments

  • Clock LoopClock Loop Posts: 1,946
    edited 2020-09-03 - 17:13:31
    Blake Koch wrote: »
    the ____ are just Blank spaces to show the indent.

    You shouldn't use the ___ to maintain indents.

    Just push the C button above, and THEN paste your code.
    [ code ]
    
    This is code
    
    [ /code ]
    
    

    normally there are no spaces in the code tag, but I had to add them, like JohnnyMac shows below.

    You can edit your first post and put the code inside the code tags.

  • JonnyMacJonnyMac Posts: 7,005
    edited 2020-09-03 - 17:03:39
    I don't write a lot of C but seem to remember encountering this when writing the PixyCam library. I found this function that declares the loop variable outside the loop, though I would normally do as you're doing.
    void showColorCodes()
    {
      int32_t nccodes;
      uint8_t i;
      
      nccodes = pixy2_getBlocks(CC_MAP, MAX_BLOCKS);
      
      if (nccodes < RESULT_OK)  
        showError(nccodes);
      else {
        print("%d color codes detected\n\n", nccodes);
        if (nccodes > 0) {
          for (i = 0; i < nccodes; i++) {
            pixy2_extractBlock(i, &b.signature);
            // printf required for octal
            printf("ccode: %3o  x: %3d  y: %3d  ", b.signature, b.xpos, b.ypos);
            printf("w: %3d  h: %3d  a: %+3d\n", b.width, b.height, b.angle);
          }
          print("\n");
        }
      }    
    }
    
    BTW... If you click on C on the forum entry toolbar you'll get code tags that will make reading your code easy without you having to insert padding. Copy and paste your code between the [ code ] and [ /code ] tags.
  • Blake KochBlake Koch Posts: 39
    edited 2020-09-03 - 17:14:07
    #include "simpletools.h"                      // Include simple tools
    char text[16];
    char pass[7] = {"abc 123"};
    
    int main()                                    // Main function
    {
        print("Enter Password: ");
        for(int i = 0; i < 16; ++i )
        {
            text[i] = getChar();
            putChar('*') 
            if(text[i] == '\r' || text[i] == '\n')
              {
                  putChar('\n');
                  text[i] = 0;
                  break;
               }
         }                    
      
      if(!strcmp(pass, text))
      {
        print("(pass does match text)\n");
      }
      else
      {
        print("(pass word does NOT match text)\n");
      }          
     
    }
    
    


    OK
  • Swing and a miss! :smiley: -- you have to paste your code between the tags.
  • There's a semicolon at the end of your for statement:
    for(int i = 0; i < 16; ++i );
    
    Remove the semicolon and see what happens.
  • mpark wrote: »
    There's a semicolon at the end of your for statement:
    for(int i = 0; i < 16; ++i );
    
    Remove the semicolon and see what happens.

    Also
    putChar('*')
    

    Needs a semicolon.
    putChar('*');
    
  • Its always the " ; "

    thank you

    It works now.
  • Cool Beans.
Sign In or Register to comment.