Skip to content

Instantly share code, notes, and snippets.

@apanda
Created January 8, 2021 20:56
Show Gist options
  • Save apanda/c6c553bc424511d60eecefb2c8f4892f to your computer and use it in GitHub Desktop.
Save apanda/c6c553bc424511d60eecefb2c8f4892f to your computer and use it in GitHub Desktop.
#include <stdio.h>
int main(int argc, char *argv[]) {
int c;
int curr_line_length;
while ((c = getc(stdin)) != EOF) {
if (c == '\n') {
printf("%d\n", curr_line_length);
curr_line_length = 0;
} else {
curr_line_length++;
}
}
if (curr_line_length > 0) {
printf("%d\n", curr_line_length);
}
return 0;
}
@apanda
Copy link
Author

apanda commented Jan 8, 2021

clang -o t -Werror -Wconditional-uninitialized test2.c
test2.c:8:28: error: variable 'curr_line_length' may be uninitialized when used here [-Werror,-Wconditional-uninitialized]
            printf("%d\n", curr_line_length);
                           ^~~~~~~~~~~~~~~~
test2.c:5:25: note: initialize the variable 'curr_line_length' to silence this warning
    int curr_line_length;
                        ^
                         = 0
1 error generated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment