#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {
char buf[64];
int n = snprintf(buf, sizeof(buf), "Hello, World! \n");
int c1_pass = (n == 15 && strcmp(buf, "Hello, World! \n") == 0);
long stdc_ver = __STDC_VERSION__;
int stdc_flag = __STDC__;
int c2_pass = (stdc_flag == 1 && stdc_ver == 201112L);
int ok_code = EXIT_SUCCESS;
int fail_code = EXIT_FAILURE;
int c3_pass = (ok_code == 0 && fail_code != 0);
printf("{\"runtime\": \"GCC C11 (mstorsjo/llvm-mingw:20260616)\", \"cases\": [\n");
printf(" {\"name\": \"hello_world_format\", \"expected\": {\"len\": 15, \"text\": \"Hello, World! \\n\"}, \"actual\": {\"len\": %d, \"text\": \"Hello, World! \\n\"}, \"passed\": %s},\n",
n, c1_pass ? "true" : "false");
printf(" {\"name\": \"c11_standard_version\", \"expected\": {\"stdc\": 1, \"version\": 201112}, \"actual\": {\"stdc\": %d, \"version\": %ld}, \"passed\": %s},\n",
stdc_flag, stdc_ver, c2_pass ? "true" : "false");
printf(" {\"name\": \"main_exit_status_convention\", \"expected\": {\"exit_success\": 0, \"exit_failure_nonzero\": true}, \"actual\": {\"exit_success\": %d, \"exit_failure_nonzero\": %s}, \"passed\": %s}\n",
ok_code, (fail_code != 0) ? "true" : "false", c3_pass ? "true" : "false");
printf("]}\n");
return 0;
}
本例需在 本地离线 Docker 容器(mstorsjo/llvm-mingw:20260616,GCC 13.3.0 C11 linux/amd64,--network none)。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程
运行环境:本地离线 Docker 容器(mstorsjo/llvm-mingw:20260616,GCC 13.3.0 C11 linux/amd64,--network none)。
入口文件:projects/c-tutorial-lab/explore-tutorial.c
本地运行步骤快速上手
- 点击上方“保存源码”保存为
explore-tutorial.c,或下载右侧课程工程包。 - 确认本地已准备 本地离线 Docker 容器(mstorsjo/llvm-mingw:20260616,GCC 13.3.0 C11 linux/amd64,--network none)。。
- 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载
课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a3264.zip
课程关联工程包(登记关联63章) · 含当前章节或实例 · mbskycom202612a3210.zip