mirror of
https://github.com/hairrrrr/C-CrashCourse.git
synced 2026-04-13 17:49:46 +08:00
4-16
This commit is contained in:
@@ -17,7 +17,7 @@ int main(void) {
|
||||
// 允许 read_word 函数多读 1 个字符,多读则代表单词长度超过 20,需要截断
|
||||
read_word(word, MAX_WORD_LEN + 1);
|
||||
word_len = strlen(word);
|
||||
if (word == 0) {
|
||||
if (word_len == 0) {
|
||||
flush_line();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ void write_line() {
|
||||
putchar(line[i]);
|
||||
else {
|
||||
spaces_to_insert = extra_space / num_words; // 遵循这个公式来增加空格
|
||||
for (j = 0; j < spaces_to_insert; j++)
|
||||
for (j = 0; j <= spaces_to_insert; j++) // 使用 = 确保至少打印一个
|
||||
putchar(' ');
|
||||
extra_space -= spaces_to_insert;
|
||||
num_words--;
|
||||
|
||||
@@ -45,13 +45,4 @@ void write_line();
|
||||
*********************************************************/
|
||||
void flush_line(void);
|
||||
|
||||
|
||||
/********************************************************
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*********************************************************/
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user