Skip to content

Commit

Permalink
new file: C-exp/exercise.c
Browse files Browse the repository at this point in the history
new file:   C-exp/helloworld.c
  • Loading branch information
SituChengxiang committed Jan 9, 2025
1 parent 5d53209 commit 725ef5d
Show file tree
Hide file tree
Showing 20 changed files with 107 additions and 0 deletions.
10 changes: 10 additions & 0 deletions C-exp/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [


]
}
28 changes: 28 additions & 0 deletions C-exp/.vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc.exe 生成活动文件",
"command": "C:\\msys64\\ucrt64\\bin\\gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
53 changes: 53 additions & 0 deletions C-exp/exercise.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// 定义学生结构体
typedef struct {
char name[100]; // 姓名字符串
char id[20]; // 学号字符串
float scores[3]; // 三门课程的成绩
} Student;

int main() {
Student student;
FILE *file;

// 提示用户输入学生的姓名和学号
printf("请输入学生的姓名:");
fgets(student.name, sizeof(student.name), stdin);
student.name[strcspn(student.name, "\n")] = 0; // 去除换行符

printf("请输入学生的学号:");
fgets(student.id, sizeof(student.id), stdin);
student.id[strcspn(student.id, "\n")] = 0; // 去除换行符

// 提示用户输入三门课程的成绩
for (int i = 0; i < 3; i++) {
printf("请输入第%d门课程的成绩:", i + 1);
scanf("%f", &student.scores[i]);
}

// 清除输入缓冲区中的换行符
getchar();

// 打开文件用于写入
file = fopen("d:\\aaa.txt", "w");
if (file == NULL) {
printf("无法打开文件!");
return 1;
}

// 将学生信息写入文件
fprintf(file, "姓名:%s 学号:%s", student.name, student.id);
for (int i = 0; i < 3; i++) {
fprintf(file, "第%d门课程成绩:%f", i + 1, student.scores[i]);
}

// 关闭文件
fclose(file);

printf("学生信息已成功写入到d:\\aaa.txt文件中。");

return 0;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions C-exp/helloworld.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
vector<string> msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};

for (const string& word : msg)
{
cout << word << " ";
}
cout << endl;
}

0 comments on commit 725ef5d

Please sign in to comment.