提交 88e61127 创建 作者: 宋海霞's avatar 宋海霞

init

上级
流水线 #156380 已失败 于阶段
用时 11 秒
# ҪɾĴļ
*.exe
*.o
*.bak
*.out
*.html
user_output*.txt
user_writefile*
*.pyc
__pycache__
# 不要删除或更改此文件
image: "registry.cn-hangzhou.aliyuncs.com/engintime/ubuntu_16.04_program:latest"
stages:
- case1
- code-analysis
variables:
TEACHERCHECK_REPO: "engintime-cs/teacher-group/shx/Test/casegroup/teachers-packet/readargv-dat-writefile-dat.git"
.codecode-runner: &codecode-runner
tags:
- ubuntu-16.04
- short-job
.codecode-analysis-runner: &codecode-analysis-runner
tags:
- ubuntu-16.04
- short-job
- code-analysis
- intranet
case1:
stage: case1
<<: *codecode-runner
script:
- python3 .vscode/test.py ./app.exe ci
only:
- master
teacher-check1:
stage: case1
<<: *codecode-runner
script:
- make
- git clone ${CODECODE_PROTOCOL}gitlab-ci-token:${CI_JOB_TOKEN}@${CODECODE_DOMAIN}/${CI_PROJECT_FORKSOURCE} template
- cd template && git checkout -b fork_position ${CI_PROJECT_FORKPOS} && cd ..
- diff template/.gitlab-ci.yml .gitlab-ci.yml -b -B -y -i --suppress-common-lines
- diff template/.vscode/test.py .vscode/test.py -b -B -y -i --suppress-common-lines
- diff template/.vscode/teacher-check.py .vscode/teacher-check.py -b -B -y -i --suppress-common-lines
- python3 .vscode/teacher-check.py ./app.exe "${TEACHERCHECK_REPO}" "${CODECODE_PROTOCOL}gitlab-ci-token:${CI_JOB_TOKEN}@${CODECODE_DOMAIN}/${TEACHERCHECK_REPO}"
only:
- master
when: manual
allow_failure: true
code-analysis:
stage: code-analysis
<<: *codecode-analysis-runner
script:
- mkdir -p build
- python3 .vscode/code-analysis.py ./app.exe
- cppcheck -v --force --enable=all --xml -I./ ./ 2> ./build/cppcheck-report.xml
- bash -c 'find ./ -regex ".*\.c\|.*\.h" | vera++ -S -s -d -c ./build/vera-report.xml'
- sonar-scanner -Dsonar.projectKey=ProjectKey-$CI_PROJECT_ID -Dsonar.projectName=$CI_PROJECT_NAME -Dsonar.links.homepage=$CI_PROJECT_URL -Dsonar.host.url=$SONAR_URL -Dsonar.login=$SONAR_LOGIN -Dsonar.gitlab.commit_sha=$CI_COMMIT_SHA -Dsonar.gitlab.ref_name=$CI_COMMIT_REF_NAME -Dsonar.gitlab.project_id=$CI_PROJECT_ID -Dsonar.gitlab.url=$CODECODE_PROTOCOL$CODECODE_DOMAIN
allow_failure: true
only:
- master
#!/bin/env python
# -*- coding: utf-8 -*-
import difflib
import sys
import argparse
import webbrowser
import os
import filecmp
import subprocess
import platform
from comtool import *
if __name__ == "__main__":
dsType, dsFileStr, resultFileType, userresultFileStr, resultFileStr = getProjInfo()
runProgCmdStr = getRunProgCmdStr(dsType, resultFileType, dsFileStr.format(1), userresultFileStr.format(1))
runCommand = "make && valgrind --xml=yes --xml-file=./build/valgrind-report.xml {0}".format(runProgCmdStr)
runCmd(runCommand)
\ No newline at end of file
#!/bin/env python
# -*- coding: utf-8 -*-
import sys
import argparse
import os
import filecmp
import subprocess
import platform
print(
"************************************************************\n"
"如果下面报告类似 ImportError: No module named 'xxx' 的错误,\n"
"说明 python 运行环境中缺少必要的包。\n"
"此时可以启动\"安装python包\"任务来修复 python 运行环境(需要连接互联网)。\n"
"************************************************************\n"
)
from colorama import Fore, init, AnsiToWin32
init(wrap=False)
stream = AnsiToWin32(sys.stderr).stream
if __name__ == "__main__":
print("gitpush.py version: 1.0")
execResult = os.system("git config credential.helper \"\" && git add . && git commit -m \"提交作业\"")
if execResult == 256 or execResult == 1:
print("\n-------- 本次提交没有任何变更,即使推送成功,也不代表远程一定有提交记录 --------")
print("-------- 请对项目中的文件进行修改后再进行提交-----------------------------------")
elif execResult != 0:
print(Fore.RED + "\n-------- 提交作业失败! 错误码: {0}--------".format(execResult), file = stream)
print(Fore.WHITE, file = stream)
exit(0)
print("\n-------------------------------------------------------------------------------")
print("请在 VSCode 顶部弹出的命令面板中输入 Git 远程库的用户名和密码。通常为 CodeCode 平台的用户名和密码。")
print("-------------------------------------------------------------------------------")
execResult = os.system("git push")
if execResult == 0:
print(Fore.GREEN + "\n-------- 提交作业成功! --------", file = stream)
print(Fore.WHITE, file = stream)
else:
print(Fore.RED + "\n--- 提交作业失败! 想解决失败问题? 使用浏览器访问下面链接即可。 ---", file = stream)
print(Fore.RED + "https://www.codecode.net/engintime/codecode/publicmanual/blob/master/GitFAQ.md", file = stream)
print(Fore.WHITE, file = stream)
\ No newline at end of file
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/app.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"preLaunchTask": "生成项目(make)",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
\ No newline at end of file
import sys
import argparse
import os
import filecmp
import subprocess
import platform
from comtool import *
if __name__ == "__main__":
dsType, dsFileStr, resultFileType, userresultFileStr, resultFileStr = getProjInfo()
runProgCmdStr = getRunProgCmdStr(dsType, resultFileType, dsFileStr.format(1), userresultFileStr.format(1))
runCommandStr = "valgrind --leak-check=full {0}".format(runProgCmdStr)
if platform.system().lower() == 'windows':
runCommandStr = "make && drmemory -ignore_kernel -leaks_only -brief -batch -- {0}".format(runProgCmdStr)
runCmd(runCommandStr)
{
"files.exclude": {
"**/*.git*": true,
"**/sonar*": true,
"**/valgrind-report.out": true,
"**/requirements.txt": true,
}
}
\ No newline at end of file
{
"version": "2.0.0",
"tasks": [
{
"label": "生成项目(make)",
"type": "shell",
"windows": {
"command": "cat \"${execPath}.tips\\env_tip.txt\" ; echo VSCode安装路径-${execPath} ; echo 正在使用makefile文件生成项目 ; cat \"${execPath}.tips\\make_tip.txt\" ; make"
},
"linux": {
"command": "echo 正在使用makefile文件生成项目 && echo VSCode安装路径-${execPath} ; echo 正在使用makefile文件生成项目 && echo \"如果报告 ld.exe: cannot open output file app.exe: Permission denied 错误,可以 重启 vscode 或者 重启计算机\" && make && echo 生成项目成功"
},
"args": [],
"group": "build",
"presentation": {
"reveal": "always",
"focus": true,
"group": "make"
},
"problemMatcher": "$gcc"
},
{
"label": "安装python包",
"type": "shell",
"windows": {
"command": "pip install -i https://mirrors.aliyun.com/pypi/simple/ -r requirements.txt"
},
"linux": {
"command": "pip3 install -i https://mirrors.aliyun.com/pypi/simple/ -r requirements.txt"
},
"args": [],
"group": "build",
"presentation": {
"reveal": "always",
"group": "setup_pip_package"
},
"problemMatcher": "$gcc"
},
{
"label": "测试(test)",
"type": "shell",
"windows": {
"command": "cat \"${execPath}.tips\\python_tip.txt\" ; python .vscode\\test.py .\\app.exe"
},
"linux": {
"command": "python3 .vscode/test.py ./app.exe"
},
"args": [],
"group": "build",
"presentation": {
"reveal": "always",
"group": "test"
},
"problemMatcher": "$gcc"
},
{
"label": "清理项目(make clean)",
"type": "shell",
"windows": {
"command": "cat \"${execPath}.tips\\env_tip.txt\" ; echo VSCode安装路径-${execPath} ; echo 正在使用makefile文件清理项目 ; make clean"
},
"linux": {
"command": "echo 正在使用makefile文件清理项目 && make clean && echo 清理项目成功"
},
"args": [],
"group": "build",
"presentation": {
"reveal": "always",
"group": "clean"
},
"problemMatcher": "$gcc"
},
{
"label": "提交作业(git push)",
"type": "shell",
"windows": {
"command": "cat \"${execPath}.tips\\python_tip.txt\" ; python .vscode\\gitpush.py"
},
"linux": {
"command": "python3 .vscode/gitpush.py"
},
"args": [],
"group": "build",
"presentation": {
"reveal": "always",
"group": "git-push"
},
"problemMatcher": "$gcc"
},
{
"label": "内存检测",
"type": "shell",
"windows": {
"command": "cat \"${execPath}.tips\\env_tip.txt\" ; echo VSCode安装路径-${execPath} ; echo 正在使用Dr.Memory检测内存 ; make ; cmd.exe /c \"drmemory -ignore_kernel -leaks_only -brief -batch -- .\\app.exe '<' input1.txt\""
},
"linux": {
"command": "echo 正在使用 Valgrind 检测内存 && make && echo ***如果提示 /bin/bash: valgrind: command not found 可使用终端命令 sudo apt install valgrind 安装(需要连接互联网)*** && valgrind --leak-check=full ./app.exe < input1.txt"
},
"args": [],
"group": "build",
"presentation": {
"reveal": "always",
"group": "test"
},
"problemMatcher": "$gcc"
},
{
"label": "内存检测2",
"type": "shell",
"windows": {
"command": "cat \"${execPath}.tips\\env_tip.txt\" ; echo VSCode安装路径-${execPath} ; echo 正在使用Dr.Memory检测内存 ; python .vscode/memorycheck.py .\\app.exe"
},
"linux": {
"command": "echo 正在使用 Valgrind 检测内存 && make && echo ***如果提示 /bin/bash: valgrind: command not found 可使用终端命令 sudo apt install valgrind 安装(需要连接互联网)*** && python3 .vscode/memorycheck.py ./app.exe"
},
"args": [],
"group": "build",
"presentation": {
"reveal": "always",
"group": "test"
},
"problemMatcher": "$gcc"
}
]
}
\ No newline at end of file
#!/bin/env python
# -*- coding: utf-8 -*-
import argparse
import difflib
import filecmp
import os
import platform
import subprocess
import sys
import webbrowser
from enum import Enum
from comtool import *
class CmpFileType:
unknown = 0
templatedatasource = 1
templateresult = 2
userprojresult = 3
def getFileCount(fileStr):
fileCount = 1
while 1:
resultFile = fileStr.format(fileCount)
if not os.path.isfile(resultFile):
fileCount -= 1
break
fileCount += 1
return fileCount
# 比较两个文件并把结果生成一份html文本
def compare_file(file1, file2, type):
returnVal = 0
if file1 == "" or file2 == "":
print('文件路径不能为空:第一个文件的路径:{0}, 第二个文件的路径:{1} .'.format(file1, file2))
sys.exit()
else:
if type == CmpFileType.userprojresult:
promptInfo = "正在比较标准答案结果文件 {0} 和用户编写的应用程序结果文件 {1}"
elif type == CmpFileType.templateresult:
promptInfo = "正在比较模板中的标准答案结果文件 {0} 和用户程序中的标准答案结果文件 {1}"
elif type == CmpFileType.templatedatasource:
promptInfo = "正在比较模板中的数据源文件 {0} 和用户程序中的数据源文件 {1}"
print(promptInfo.format(file1, file2), end=': ')
sys.stdout.flush()
if os.path.isfile(file1) and os.path.isfile(file2) and advanced_file_compare(file1, file2):
print("文件相同")
sys.stdout.flush()
returnVal = 1
else:
print("文件不同")
sys.stdout.flush()
return returnVal
if __name__ == "__main__":
dsType, dsFileStr, resultFileType, userresultFileStr, resultFileStr = getProjInfo()
# 检查数据源文件一致性
dsFileCount = getFileCount(dsFileStr)
for i in range(1, dsFileCount + 1):
dsFile = dsFileStr.format(i)
userresultFile = userresultFileStr.format(i)
runProgCommand = getRunProgCmdStr(dsType, resultFileType, dsFile, userresultFile)
runCmd(runProgCommand)
print("正在检查{0}文件的一致性".format(dsFile))
sys.stdout.flush()
if compare_file("template/{0}".format(dsFile), dsFile, CmpFileType.templatedatasource) == 0:
runCmpCommand = "diff template/{0} {0} -b -B -y -i --suppress-common-lines".format(dsFile)
runCmd(runCmpCommand)
exit(1)
# 检查输出文件的一致性
resultFileCount = getFileCount(resultFileStr)
for i in range(1, resultFileCount + 1):
dsFile = dsFileStr.format(i)
userresultFile = userresultFileStr.format(i)
runProgCommand = getRunProgCmdStr(dsType, resultFileType, dsFile, userresultFile)
runCmd(runProgCommand)
resultFile = resultFileStr.format(i)
print("正在检查{0}文件的一致性".format(resultFile))
sys.stdout.flush()
if compare_file( "template/{0}".format(resultFile), resultFile, CmpFileType.templateresult) == 0:
runCmpCommand = "diff template/{0} {0} -b -B -y -i --suppress-common-lines".format(resultFile)
runCmd(runCmpCommand)
exit(1)
# 执行完成文件完整性检查
os.system("fileidentity.sh")
if sys.argv[2] != "":
# 克隆教师检查项目,参数:${CODECODE_PROTOCOL}gitlab-ci-token:${CI_JOB_TOKEN}@${CODECODE_DOMAIN}/${TEACHERCHECK_REPO}
runCloneCommand = "git clone {0} teacher_check".format(sys.argv[3])
runCmd(runCloneCommand)
teaCheckCount = getFileCount("teacher_check/" + dsFileStr)
for i in range(1, teaCheckCount + 1):
print("正在检查附加算例case{0}".format(i))
sys.stdout.flush()
# runProgCommand = "./app.exe < teacher_check/input{0}.txt > user_output{0}.txt".format(i)
# execResult = os.system(runProgCommand)
dsFile = "teacher_check/{0}".format(dsFileStr.format(i))
userresultFile = userresultFileStr.format(i)
runProgCmdStr = getRunProgCmdStr(dsType, resultFileType, dsFile, userresultFile)
runCmd(runProgCmdStr)
resultFile = resultFileStr.format(i)
if compare_file( "teacher_check/{0}".format(resultFile), userresultFile, CmpFileType.userprojresult) == 0:
runCmpCommand = "diff teacher_check/{0} {1} -b -B -y -i -W 100".format(resultFile, userresultFile)
runCmd(runCmpCommand)
exit(1)
# 处理读取指定文件
if teaCheckCount == 0:
specifyfile = "teacher_check/" + getSpecifyfileStr()
if os.path.isfile(specifyfile):
runCpCommand = "cp teacher_check/{0} {0}".format(specifyfile)
runCmd(runCpCommand)
print("正在检查附加算例")
userresultFile = userresultFileStr.format(1)
runProgCmdStr = getRunProgCmdStr(dsType, resultFileType, "", userresultFile)
runCmd(runProgCmdStr)
resultFile = resultFileStr.format(1)
if compare_file( "teacher_check/{0}".format(resultFile), userresultFile, CmpFileType.userprojresult) == 0:
runCmpCommand = "diff teacher_check/{0} {1} -b -B -y -i -W 100".format(resultFile, userresultFile)
runCmd(runCmpCommand)
exit(1)
# 执行完成附加算例检查
os.system("extracase.sh")
\ No newline at end of file
#!/bin/env python
# -*- coding: utf-8 -*-
import difflib
import sys
import argparse
import webbrowser
import os
import filecmp
import subprocess
import platform
from enum import Enum
from comtool import *
class Color(Enum):
white = 0
green = 1
red = 2
yellow = 3
bCI = False
if len(sys.argv) > 2 and sys.argv[2] == "ci":
bCI = True
if bCI == False:
print(
"************************************************************\n"
"如果下面报告类似 ImportError: No module named 'xxx' 的错误,\n"
"说明 python 运行环境中缺少必要的包。\n"
"此时可以启动\"安装python包\"任务来修复 python 运行环境(需要连接互联网)。\n"
"************************************************************\n"
)
from colorama import Fore, init, AnsiToWin32
init(wrap=False)
stream = AnsiToWin32(sys.stderr).stream
red = lambda text: '\033[0;31;1m' + text + '\033[0m'
green = lambda text: '\033[0;32;1m' + text + '\033[0m'
yellow = lambda text: '\033[0;33;1m' + text + '\033[0m'
# 比较两个文件并把结果生成一份html文本
def compare_file(file1, file2, seqNum, caseCount, bCI, resultFileType, dsType):
returnVal = 0
if file1 == "" or file2 == "":
print('文件路径不能为空:第一个文件的路径:{0}, 第二个文件的路径:{1} .'.format(file1, file2))
sys.exit()
else:
print("正在比较标准答案结果文件 {0} 和用户编写的应用程序结果文件 {1}".format(file1, file2), end=': ')
if os.path.isfile(file1) and os.path.isfile(file2) and advanced_file_compare(file1, file2):
print("文件相同")
score = 40
if seqNum == caseCount:
score = 100
else:
score = score + 60 / caseCount * seqNum
if bCI :
promptInfo = "Case{0} 验证成功".format(seqNum)
outputPromptInfo(bCI, promptInfo, Color.green)
print("exec-score", int(score))
else:
promptInfo = "Case{0} 验证成功, 分数: {1}".format(seqNum, int(score))
outputPromptInfo(bCI, promptInfo, Color.green)
if seqNum == caseCount:
promptInfo = "恭喜你通过了所有测试!"
outputPromptInfo(bCI, promptInfo, Color.green)
returnVal = 1
return returnVal
else:
print("文件不同")
promptInfo = "Case{0} 验证失败".format(seqNum)
outputPromptInfo(bCI, promptInfo, Color.green)
if bCI == False and resultFileType != ResultFileType.writedat:
text1_lines = read_file(file1)
text2_lines = read_file(file2)
diff = difflib.HtmlDiff() # 创建HtmlDiff 对象
result = diff.make_file(text1_lines, text2_lines) # 通过make_file 方法输出 html 格式的对比结果
# 将结果写入到result_comparation.html文件中
try:
with open('result_comparation.html', 'a+', encoding="utf-8") as result_file:
dsFile = getDataSourceFileStr(dsType).format(seqNum)
resultfile = getResultFileStr(resultFileType).format(seqNum)
userresultfile = getUserResultFileStr(resultFileType).format(seqNum)
promptContent = "<p>Case {0} 验证失败。使用的数据源文件是 {1}。</br>标准答案结果文件 {2}(左边)与用户编写的应用程序结果文件 {3}(右边)的比较结果:</p>".format(seqNum, dsFile, resultfile, userresultfile)
result = promptContent + result
result_file.write(result)
except IOError as error:
print('写入html文件错误:{0}'.format(error))
finally:
return returnVal
else:
return returnVal
# 1表示绿色,2表示红色,3表示黄色
def outputPromptInfo(bCI, promptInfo, color):
if bCI :
if color == Color.green:
print(green(promptInfo))
elif color == Color.red:
print(red(promptInfo))
elif color == Color.yellow:
print(yellow(promptInfo))
else:
print(promptInfo)
else:
if color == Color.green:
print(Fore.GREEN + promptInfo, file = stream)
elif color == Color.red:
print(Fore.RED + promptInfo, file = stream)
elif color == Color.yellow:
print(Fore.YELLOW + promptInfo, file = stream)
else:
print(promptInfo)
print(Fore.WHITE, file = stream)
sys.stdout.flush()
if __name__ == "__main__":
compResultFile = "result_comparation.html"
if os.path.isfile(compResultFile):
os.remove(compResultFile)
promptInfo = "正在使用 makefile 文件生成项目"
outputPromptInfo(bCI, promptInfo, Color.green)
execResult = os.system("make")
if execResult != 0:
errorInfo = "生成项目失败"
outputPromptInfo(bCI, errorInfo, Color.red)
exit(1)
else:
score = 40
if not (os.path.isfile("output1.txt") or os.path.isfile("writefile1.txt") or os.path.isfile("writefile1.dat")):
score = 100
if bCI:
promptInfo = "生成项目成功"
outputPromptInfo(bCI, promptInfo, Color.green)
promptInfo = "exec-score {0}".format(score)
print(promptInfo)
else:
promptInfo = "生成项目成功, 分数 {0}".format(score)
outputPromptInfo(bCI, promptInfo, Color.green)
dsType, dsFileStr, resultFileType, userresultFileStr, resultFileStr = getProjInfo()
# resultFileType = getResultFileType()
if resultFileType == ResultFileType.nooutput:
exit(0)
# resultFileStr = getResultFileStr(resultFileType)
# userresultFileStr = getUserResultFileStr(resultFileType)
# 获取case的数量
caseCount = 1
while 1:
resultFile = resultFileStr.format(caseCount)
if not os.path.isfile(resultFile):
caseCount -= 1
break
caseCount += 1
# dsType = getDataSourceFileType()
# dsFileStr = getDataSourceFileStr(dsType)
seqNum = 1
while 1:
dsFile = dsFileStr.format(seqNum)
resultFile = resultFileStr.format(seqNum)
userresultFile = userresultFileStr.format(seqNum)
if seqNum == 1 and not os.path.isfile(resultFile):
promptInfo = "该项目未提供自动化验证功能"
if bCI :
print(red(promptInfo))
else:
print(Fore.RED + "该项目未提供自动化验证功能", file = stream, end='')
print(Fore.WHITE, file = stream)
break
if not os.path.isfile(resultFile):
break
if bCI :
print(yellow("标准答案结果文件和用户输出结果文件的比较原则是:比较时忽略行尾空白字符和文件末尾的空白行。"))
else:
print(Fore.YELLOW + "标准答案结果文件和用户输出结果文件的比较原则是:比较时忽略行尾空白字符和文件末尾的空白行。", file = stream, end='')
print(Fore.WHITE, file = stream)
if dsType == DataSourceFileType.noinput:
print("正在验证 case{0}".format(seqNum))
else:
print("正在使用数据源文件 {0} 验证 case{1}".format(dsFile, seqNum))
runCmdStr =getRunProgCmdStr(dsType, resultFileType, dsFile, userresultFile)
promptInfo = "正在执行命令: {0}".format(runCmdStr)
outputPromptInfo(bCI, promptInfo, Color.white)
if bCI == False:
promptInfo = "提示:如果验证程序长时间未结束,说明应用程序中可能存在死循环。请停止验证程序(Ctrl+c),修改应用程序后再验证。"
outputPromptInfo(bCI, promptInfo, Color.yellow)
execResult = os.system(runCmdStr)
if execResult != 0:
errorInfo = "应用程序执行异常,返回值:{0}。".format(execResult)
outputPromptInfo(bCI, errorInfo, Color.red)
exit(1)
if os.path.isfile(resultFile) and os.path.isfile(userresultFile):
if compare_file(resultFile, userresultFile, seqNum, caseCount, bCI, resultFileType, dsType) == 0:
if bCI :
if dsType != DataSourceFileType.noinput:
print("使用的数据源文件是 {0}。".format(dsFile))
print("标准答案结果文件 {0}(左边)与用户编写的应用程序结果文件 {1}(右边)的比较结果:".format(resultFile, userresultFile))
runCommand = "diff {0} {1} -b -B -y -i -W 100".format(resultFile, userresultFile)
execResult = os.system(runCommand)
else:
if resultFileType != 3:
promptInfo = "查看文件比较结果可帮助你查找验证失败的原因。方法是:\n选择 View 菜单中的 Explorer 打开文件列表,右键点击 result_comparation.html 文件,在弹出的菜单中选择 Open Preview"
outputPromptInfo(bCI, promptInfo, Color.red)
else:
print("选择 View 菜单中的 Explorer 打开文件列表,右键点击 writefile*.dat文件或user_writefile*.dat文件,在弹出的菜单中选择 Open With...,再选择 Hex Editor ")
exit(1)
seqNum = seqNum + 1
void fun()
{
int a, b;
b = a;
}
#include <stdio.h>
#include <stdlib.h>
void fun();
int main(int argc, char *argv[])
{
int x = 21, y = 22;
float m = 5.56;
int *p = malloc(8);
fun();
if( argc == 2 )
{
printf("The argument supplied is %s\n", argv[1]);
}
FILE* fp2 = fopen(argv[1], "rb");
if (fp2 != NULL) {
fread(&x, sizeof(int), 1, fp2);
fread(&y, sizeof(int), 1, fp2);
fread(&m, sizeof(float), 1, fp2);
}
fclose(fp2);
FILE* fp = fopen(argv[2], "wb");
unsigned char buf[256];
if (fp != NULL) {
fwrite(&y, sizeof(int), 1, fp);
fwrite(&x, sizeof(int), 1, fp);
m += 2.5;
fwrite(&m, sizeof(float), 1, fp);
}
fclose(fp);
return 0;
}
# 不要删除或修改此文件
DIR_INC = .
DIR_SRC = .
DIR_OBJ = .
DIR_BIN = .
SRC = $(wildcard ${DIR_SRC}/*.c)
OBJ = $(patsubst %.c,${DIR_OBJ}/%.o,$(notdir ${SRC}))
TARGET = app.exe
BIN_TARGET = ${DIR_BIN}/${TARGET}
CC = gcc
CFLAGS = -g -w -fmax-errors=10 -std=c99 -fsigned-char -I${DIR_INC}
${BIN_TARGET}:${OBJ}
@echo --- build executable file: $@
$(CC) $(OBJ) -o $@
${DIR_OBJ}/%.o:${DIR_SRC}/%.c
@echo --- build object file: $@
$(CC) $(CFLAGS) -c $< -o $@
RM = @echo 无法识别的平台。无法删除文件
ifdef OS
RM = del /Q
else
ifeq ($(shell uname), Linux)
RM = rm -f
endif
endif
clean:
$(RM) *.exe *.o result_comparation.html user_output* user_writefile*
\ No newline at end of file
添加文件
添加文件
添加文件
# 求分段函数
\ No newline at end of file
# -*- coding: utf-8 -*-
###### 不要列出标准库中已包含的包,例如:Math,time等,如果列出将出现如下错误:######
###### RuntimeError: Package '**' must not be downloaded from pypi ######
colorama
\ No newline at end of file
# 不要删除或修改此文件
# required metadata
sonar.language=c
# path to source directories (required)
sonar.sources=./
# path to the build artifact
sonar.artifact.path=build/app
# paths to the reports
sonar.c.cppcheck.reportPath=./build/cppcheck-report.xml
#sonar.c.pclint.reportPath=./build/pclint-report.xml
#sonar.c.coverage.reportPath=./build/gcovr-report*.xml
#sonar.c.coverage.itReportPath=./build/gcovr-report*.xml
#sonar.c.coverage.overallReportPath=./build/gcovr-report*.xml
sonar.c.valgrind.reportPath=./build/valgrind-report.xml
sonar.c.vera.reportPath=./build/vera-report.xml
#sonar.c.rats.reportPath=./build/rats-report.xml
#sonar.c.xunit.reportPath=./build/xunit-report.xml
#sonar.c.drmemory.reportPath=./build/drmemory-logs/**/results.txt
sonar.c.includeDirectories=/usr/include/,/usr/include/linux,/usr/include/x86_64-linux-gnu/bits,/usr/include/x86_64-linux-gnu/sys,/usr/include/c++/5/tr1,./
添加文件
添加文件
添加文件
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论