C语言使用标准输入输出流或者windows或者Linux输入输出流
C语言用户层的输出流✅ 1. 使用 C 标准库的 printf(stdout)123456#include <stdio.h>int main() { printf("Hello from C stdout (printf)!\n"); return 0;}
✅ 2.示例代码:C 标准输入输出流使用1. 标准 C 库标准输出流函数(跨平台通用)
这些函数是 C 标准库的一部分,在 Linux 和 Windows 上均可使用:
printf / fprintf
123printf("Hello, World!\n"); // 输出到 stdoutfprintf(stdout, "Hello, stdout!\n"); // 等价于 printffprintf(stderr, "Error: something wrong\n"); // 输出到 stderr
puts / fputs
1 ...
C语言程序中调用windows命令
C语言程序中调用windows命令在 C 语言程序中调用 Windows 命令,可以通过以下几种方式实现:
1. 使用 system() 函数(最简单)system() 是标准 C 库函数,直接执行命令行字符串:
1234567#include <stdlib.h>int main() { system("dir"); // 执行 `dir` 命令(列出当前目录) system("ping 127.0.0.1"); // 执行 ping 命令 return 0;}
优点:简单易用,跨平台(在 Linux 下也可用,但命令不同)。
缺点:
会启动 cmd.exe 子进程,性能较低。
无法直接获取命令的输出(仅显示在控制台)。
2. 使用 popen() 函数(捕获命令输出)popen() 可以执行命令并读取其输出(通过管道):
123456789101112131415161718#include <stdio.h>#include <stdlib. ...
GNUmakefile
Makefile (notes and examples)This document explains how to compile C programs with gcc and how to use Makefiles to automate builds. It includes step-by-step commands, split compilation, simple Makefiles, and improved templates with variables and pattern rules.
1. How to compile a simple program
Create main.c:
11. Create `main.c`:
Write this example code into main.c:
123gcc -o hello main.o defs.ogcc -c main.c -o main.o
Makefile (notes and examples) This document explains how to compile C prog ...
Linux链接静态库与动态库并且打包程序
[toc]
链接静态库1.自写链接动态库
1gcc -o httpc httpc.c -lssl -lcrypto
2.第三方链接动态库1.自写链接静态库
1gcc -o LinClient LinClient.c -static -lssl -lcrypto
2.第三方打包程序1.打包一个链接OpenSSl的程序
安装 OpenSSL12sudo apt updatesudo apt install openssl libssl-dev
编写代码
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 ...
9.C语言使用glfw3与opengl在vs2022中开发窗口程序
[toc]
C语言使用glfw3与opengl在vs2022中开发窗口程序1.准备开发环境
使用vkpkg安装glfw3.
使用vkpkg安装glad
2.使用glfw创建一个窗口程序12345678910111213141516171819202122232425262728293031#include <GLFW/glfw3.h> #include <stdio.h>int main(){ glfwInit(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);#ifdef __APPLE__ glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);#endif GLFWwindow* windo ...
8.C++使用OpenGl画点线面
[toc]
C++使用OpenGl画点线面1.点1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071#include <glut.h>#include <windows.h>#define WINDOW_NAME "Drawing Points"// Vertex data for 5 pointsGLfloat points[][2] = { {100.0f, 100.0f}, {200.0f, 100.0f}, {300.0f, 100.0f}, {400.0f, 100.0f}, {500.0f, 100.0f}};// Function to render the scen ...
7.C语言在windows平台使用opengl图形库画窗口图形
[toc]
在c语言程序中使用openGL配置环境
下载glut库
将头文件添加项目里,将静态库与动态库放置项目文件夹里
编译版本选择x86,库文件只支持x86不支持x64
使用openGL画一个茶壶OpenGL(十六) 鼠标、键盘交互响应事件
OpenGL(十六) 鼠标、键盘交互响应事件
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 ...
6.C++使用Direct3D9画点线面
[toc]
C++使用Direct3D画点线面1.点1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931 ...
5.C++使用Direct2D画点线面
[toc]
#C++使用Direct2D画点线面1.Direct2D绘制点123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129#include <windows.h>#include <d2d1.h>#pragma comment(lib, "d2d1.lib")// 全局变量ID2D1Factory* pFactory = NULL;ID2D1HwndRenderTarget* pRenderTarget = NULL;void Creat ...
4.在windows窗口程序中画立体图形
[toc]
在windows窗口程序中画立体图形1.在windows窗口程序中画正方体123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116#include <windows.h>// 绘制正方体的函数void DrawCube(HDC hdc) { // 设置正方体的参数 int size = 100; // 正方体的边长 int offsetX = 150; // 正方体的X坐标 int offsetY = 100; // 正方体的Y坐标 // 计算正方体的顶点 POINT front[4] = ...
