#include "scc_sstream.h" #include int main(int argc, char **argv) { const char *filename = (argc > 1) ? argv[1] : __FILE__; // 默认读取自身 scc_sstream_t stream; scc_sstream_ring_t *ring; // 初始化 if (scc_sstream_init(&stream, filename, 16) != 0) { fprintf(stderr, "Failed to initialize stream for %s\n", filename); return 1; } ring = scc_sstream_ref_ring(&stream); Assert(ring != null); printf("Reading file: %s\n", filename); scc_sstream_char_t elem; cbool ok; int char_count = 0; int line_count = 0; // 循环读取所有字符 while (1) { scc_ring_next_consume(*ring, elem, ok); if (!ok) break; // 文件结束或错误 char_count++; if (elem.character == '\n') line_count++; // 打印前 200 个字符的位置信息(避免刷屏) if (char_count <= 200) { printf("char[%d]: '%c' (line %zu, col %zu)\n", char_count, elem.character == '\n' ? ' ' : elem.character, // 换行符显示为空格 elem.pos.line, elem.pos.col); } } printf("\nSummary:\n"); printf(" Total characters: %d\n", char_count); printf(" Total lines: %d\n", line_count); // 释放资源 scc_sstream_drop_ring(ring); scc_sstream_drop(&stream); return 0; }