Checking for an "end of line" in a C-string -


i want input user maximum length of 30 chars string , check whether contains end of line.

this tried write far:

int main(void) { int i; char* command = (char*)calloc(31, sizeof(char)); while (0 < 1) {     scanf("%s", command);     (i = 0; <= strlen(command); ++i) {         if (command[i] == '\n')             printf("here");     }     if (strcmp(command, "quit") == 0)         break; } 

the idea check whether command given user input "legal" - of length < 31. when run code, never prints "here" regardless of length of input.

this because scanf() doesn't include linefeed, considers whitespace , uses whitespace separate values converts. use strlen()'s return value.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -