Hi all, title. Basically this is my readline
Code:
int read_line(char str[], int n){
int ch, i = 0;
while (isspace(ch = getchar()))
;
while (ch != '\n' && ch != EOF) {
if (i < n)
str[i++] = ch;
ch = getchar();
}
str[i] = '\0';
return i;
}
and this is my main code
Code:
printf("Enter word: "); read_line(word_str,MAX_LEN);
if (word_str[0] == '\0')
break;
I need to trigger the break when the user makes an empty input. E.g. after entering a word, when program prints "Enter word" again the user just hits enter. But currently for my program what happens is that enter just goes to the next line until i actually input a character/string. Thank you all for the help.