Shop OBEX P1 Docs P2 Docs Learn Events
gets problem, for me — Parallax Forums

gets problem, for me

RsadeikaRsadeika Posts: 3,837
edited 2012-09-12 06:39 in Propeller 1
It has to be a very simple explanation, but I do not see it. In the program below, I expect, when I enter "quit", that it will break out of the while loop and the program ends. But, it never breaks out of the loop, what am I missing here?

Ray

Board Type - DNA:SQI; Compiler Type - C; Memory Model - CMM; Optimization - Os Size.
/**
 * @file genTest.c
 * This is the main genTest program start point.
 */
#include <stdio.h>
#include <propeller.h>
/**
 * Main program function.
 */
int main(void)
{
    char buffer[80];
    waitcnt(CNT + CLKFREQ);
    
    while(1)
    {
        printf("> ");
        gets(buffer);
        if (buffer == "quit") break;
    }
        
    return 0;
}

Comments

  • Dave HeinDave Hein Posts: 6,347
    edited 2012-09-12 06:39
    Use !strcmp(buffer, "quit") instead of buffer == "quit". strcmp will compare the contents of two strings and return zero if they're equal. buffer == "quit" is comparing the address of buffer with the address of "quit", and they will never be equal since they are stored at different addresses.
Sign In or Register to comment.