#include int main(int argc, char *argv[]) { if (argc != 2) { printf("Usage: %s [file.c]\n", argv[0]); return 1; } FILE *file = fopen(argv[1], "r"); if (!file) { printf("Error opening file\n"); return 1; } char line[1024]; int sloc = 0; int in_multiline = 0; while (fgets(line, sizeof(line), file)) { char *p = line; int has_code = 0; while (*p) { if (in_multiline) { if (p[0] == '*' && p[1] == '/') { in_multiline = 0; p += 2; continue; } } else { if (p[0] == '/' && p[1] == '*') { in_multiline = 1; p += 2; continue; } if (p[0] == '/' && p[1] == '/') break; if (p[0] != ' ' && p[0] != '\t' && p[0] != '\n' && p[0] != '\r') { has_code = 1; } } p++; } if (has_code && !in_multiline) sloc++; } fclose(file); printf("SLOC Count: %d\n", sloc); return 0; }