使用tcc读写文本文件

本文介绍了如何利用TCC进行文本文件的读写操作。首先展示了使用TCC编译C程序并写入文本文件的过程,接着讲解了编写C程序读取文本文件的方法,并通过运行生成的exe文件展示读取效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、使用tcc写入文本文件

使用tcc向文本文件写入内容,步骤如下:
首先使用notepad++编写.c程序

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
 
int main()
{
	FILE *fpWrite;
	char cl,filename[15];
	printf("please input the filename:");
	scanf("%s",filename);
	
	if ((fpWrite=fopen(filename,"w"))==NULL)//打开文件,文件类型为写入,且如果无此文件,返回0
	{
		return 0;
	}
	printf("please input the content:");
		cl=getchar();
		cl=getchar();
	while( cl !=EOF)
	{
		fputc(cl,fpWrite);//把cl输出到磁盘文件里去
		cl=getchar();
	}
	fclose(fpWrite);
}
	

写好.c文件后,命名为xie.c,在cmd中使用tcc运行.c文件,生成xie.exe
在这里插入图片描述
运行后,输入要写入的文件名称,写入内容后回车,再按ctrl+z(即EOF,为文件的结束符),
在这里插入图片描述
写入的文本文件内容如下:

使用C语言,使用vscode软件,使用g++编译器,使用simplified chinese(gbk)编码环境,做一个家庭菜谱管理系统,要实现以下功能:1.添加菜谱2.修改菜谱3.删除菜谱4.查询菜谱5.查看全部菜谱 菜谱包括:菜名(菜谱名),分类,食材,制作步骤,谁喜欢吃 其中2.修改菜谱 通过菜谱名里可以单独选择内容,比如单独修改分类 4.查询菜谱 可以选择通过菜名查找,通过分类查找,通过食材查找,通过谁喜欢吃查找 给出这个系统的完整c和h文件,给出每个文件中完整的代码和注释 对于要编代码的WJ文件夹,同目录下有.vscode文件夹,文件夹中有以下四个文件: c_cpp_properties.json内容为: { "configurations": [ { "name": "Win64", "includePath": ["${workspaceFolder}/**"], "defines": ["_DEBUG", "UNICODE", "_UNICODE"], "windowsSdkVersion": "10.0.18362.0", "compilerPath": "D:/MinGW/bin/g++.exe", "cStandard": "c17", "cppStandard": "c++17", "intelliSenseMode": "gcc-x64" } ], "version": 4 } launch.json内容为: { "version": "0.2.0", "configurations": [ { "name": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceRoot}", "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "D:\\MinGW\\bin\\gdb.exe", "preLaunchTask": "g++", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] }, { "name": "C/C++: g++.exe 构建和调试活动文件", "type": "cppdbg", "request": "launch", "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "D:/MinGW/bin", "environment": [], "externalConsole": false, "MIMode": "gdb", "miDebuggerPath": "D:\\MinGW\\bin\\gdb.exe", "setupCommands": [ { "description": "为 gdb 启用整齐打印", "text": "-enable-pretty-printing", "ignoreFailures": true }, { "description": "将反汇编风格设置为 Intel", "text": "-gdb-set disassembly-flavor intel", "ignoreFailures": true } ], "preLaunchTask": "C/C++: g++.exe 生成活动文件" } ] } settings.json内容为: { "files.associations": { "*.py": "python", "iostream": "cpp", "*.tcc": "cpp", "string": "cpp", "unordered_map": "cpp", "vector": "cpp", "ostream": "cpp", "new": "cpp", "typeinfo": "cpp", "deque": "cpp", "initializer_list": "cpp", "iosfwd": "cpp", "fstream": "cpp", "sstream": "cpp", "map": "c", "stdio.h": "c", "algorithm": "cpp", "atomic": "cpp", "bit": "cpp", "cctype": "cpp", "clocale": "cpp", "cmath": "cpp", "compare": "cpp", "concepts": "cpp", "cstddef": "cpp", "cstdint": "cpp", "cstdio": "cpp", "cstdlib": "cpp", "cstring": "cpp", "ctime": "cpp", "cwchar": "cpp", "exception": "cpp", "ios": "cpp", "istream": "cpp", "iterator": "cpp", "limits": "cpp", "memory": "cpp", "random": "cpp", "set": "cpp", "stack": "cpp", "stdexcept": "cpp", "streambuf": "cpp", "system_error": "cpp", "tuple": "cpp", "type_traits": "cpp", "utility": "cpp", "xfacet": "cpp", "xiosbase": "cpp", "xlocale": "cpp", "xlocinfo": "cpp", "xlocnum": "cpp", "xmemory": "cpp", "xstddef": "cpp", "xstring": "cpp", "xtr1common": "cpp", "xtree": "cpp", "xutility": "cpp", "stdlib.h": "c", "string.h": "c" }, "editor.suggest.snippetsPreventQuickSuggestions": false, "aiXcoder.showTrayIcon": true } tasks.json内容为: { "version": "2.0.0", "tasks": [ { "label": "g++", "command": "g++", "args": [ "-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}.exe" ], "problemMatcher": { "owner": "cpp", "fileLocation": [ "relative", "${workspaceRoot}" ], "pattern": { "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$", "file": 1, "line": 2, "column": 3, "severity": 4, "message": 5 } }, "group": "build" }, { "type": "cppbuild", "label": "C/C++: g++.exe 生成活动文件", "command": "D:/MinGW/bin/g++.exe", "args": [ "-fdiagnostics-color=always", "-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe" ], "options": { "cwd": "D:/MinGW/bin" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true }, "detail": "调试器生成的任务。" } ] }
最新发布
07-04
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值