Shop OBEX P1 Docs P2 Docs Learn Events
question on for loop? — Parallax Forums

question on for loop?

Hello all,Newbie here, I have a little programing experience in asm & VB6, but nothing to write home about. Just got my activity bot, and seem to have hit a snag on the last part of getting text from the terminal. http://learn.parallax.com/propeller-c-start-simple/get-text-terminalget text.c works fine, password check.c works fine. But on the last part under YOUR TURN - a custom version using getChar() and manually looping through  the char array - I seem to have hit a snag. The code compiles which makes it difficult to figure out what's wrong - Said my post was too long, so, attached text file explains :lol:

Comments

  • Could it be that text has a 0 appended at the end and pass does not?
    John Abshier
  • TorTor Posts: 2,010
    Move the strcmp test *after* the foor-loop.
  • Thanks for the input guys, - got it to work - checking appended 0's put me on the right path - Thanks! - the loop example given to loop through a char array works fine -but combining it with strcmp (my addition, not propeller) gets dicey = different data types. 
    So 1st the loop for text[] needs to be limited to the length of the password (pass[7]) to check, else it's not possible to have a match - too many char, not enough char, wrong char, will always throw it to the doesn't match - 
    2nd forgot strcmp returns 0 by default - IF statements return 1 if true by default - 
    so moral is: !strcmp returns 1, if text[] is the right length and right chars, which satisfies the IF statement's true condition    -  almost completly crazy now - lol! 
Sign In or Register to comment.