-
-
Notifications
You must be signed in to change notification settings - Fork 135
Open
Description
trailing_blanks.c is buggy because it assumes that there is always a new line.
The correct version:
void remove_trailing_blank(char line[], int len) {
int end = len - 1;
int has_newline = (line[end] == '\n');
if (has_newline) {
end--;
}
while (end >= 0 && (line[end] == ' ' || line[end] == '\t')) {
end--;
}
if (has_newline) {
line[++end] = '\n';
}
line[end + 1] = '\0';
}
Metadata
Metadata
Assignees
Labels
No labels