轻松的编程学习
首页
题库
学习路径
在线商城
能力地图
下载应用
登录 / 注册
菜单
交付:五条验收条款一起过
👁️ 0 人浏览
💬 0 人评论
❤️ 添加收藏
(本条路线统一用
gcc -std=c11 -O0 -Wall
编译)前两条已经写好了,把后三条补上。
提交你的答案
请登录后提交答案。
去登录
← 🔴 第四步:正常路和失败路都要走一遍
打印这件事,C++ 强在哪 →
更多题目
改成"你好,有词"
输出"100 分"
把年龄改成 20
输出学习天数 30
修复:给文字加引号
修复:补上右括号
代码编辑器
语言:
python3
c11
cpp17
Ctrl
+
Enter
运行
👩🏫 AI
▶ 运行代码
重置代码
打印代码
#include <stdio.h> #include <stdlib.h> #include <string.h> static int got = 0, gave = 0; #define OK 0 #define E_INPUT 2 static int tool(int argc, char **argv, int *out_rows, int *out_total) { if (argc < 2) return E_INPUT; FILE *f = tmpfile(); if (f == NULL) return E_INPUT; for (int i = 1; i < argc; i++) fprintf(f, "%s\n", argv[i]); rewind(f); char **kept = malloc((size_t)(argc - 1) * sizeof(char *)); got++; char word[32]; int rows = 0, total = 0; while (rows < argc - 1 && fscanf(f, "%31s", word) == 1) { kept[rows] = malloc(strlen(word) + 1); got++; strcpy(kept[rows], word); total += (int)strlen(word); rows++; } fclose(f); for (int i = 0; i < rows; i++) { free(kept[i]); gave++; } free(kept); gave++; *out_rows = rows; *out_total = total; return OK; } int main(void) { char *fake[] = {"tool", "apple", "pear", "fig", NULL}; int rows = 0, total = 0, rows2 = 0, total2 = 0; int rc = tool(4, fake, &rows, &total); int rc2 = tool(1, fake, &rows2, &total2); /* 五条验收条款,1 表示过 */ int c1 = (rc == OK); /* 正常路:成功 */ int c2 = (rows == 3); /* 正常路:条数对 */ /* TODO: c3 —— 正常路的字符总数是 12 */ int c3 = 0; /* TODO: c4 —— 参数不够那次,返回的是 E_INPUT 而不是 OK */ int c4 = 0; /* TODO: c5 —— 两次跑完,要的块数和还的块数相等 */ int c5 = 0; printf("%d/%d/%d/%d/%d\n", c1, c2, c3, c4, c5); return 0; }
本次输入:
输出:
👩🏫
AI
请登录后使用 AI 老师
×
登录后可获得解题思路、提示与错误分析。
去登录
关闭
🎉
恭喜你,回答正确!
系统判定:正确
我知道了
💬 题目评论
提交
全部评论
全部评论