loops - fgets in C language multiple prints after get string -
i have code , want loop finish when user gives "###". int main(){ char s[10]; printf("give string: "); fgets(s,11,stdin); do{ printf("give string: "); fgets(s,11,stdin); }while ( s!="###" ); return 0; } so far it's ok, when user gives input bigger 11 characters have multiple prints of "give string". try scanf , did right. can give me solution fgets ? i mean output looks this. c string doesn't support direct comparison, need strcmp that, so while ( s!="###" ) should while(strcmp(s,"###")) also you'd need remove \n fgets (so strcmp ignore \n ). do..while should like: do{ printf("give string: "); fgets(s,11,stdin); s[strlen(s) - 1] = '\0'; } while (strcmp(s,"###"));