Rust 简单输入输出以及读取文件 - 例子代码
在这里分享一个我写的 Rust 例子,用到了输入输出和文件读取。 123456789101112131415161718192021222324252627/// # 学习 Rust 中的标准输入/// 首先我们要导入 stdin/// `use std::io::stdin`use std::io::{self, stdin};use std::io::prelude::*;use std::fs::File;fn main() -> io::Result<()> { println!("请输入一些内容个 hello 变量:"); let mut hello = String::new(); stdin().read_line(&mut hello)?; // 程序运行到这里会停住等你输入文字 // 打印 hello 变量 println!("variable hello>>>: {hello}"); //...
C语言字符串处理相关笔记
gets()函数原型: 1char * gets (char *__str); 功能:从标准输入读入字符,并保存到__str指定的内存空间,直到出现换行符或读到文件结尾为止。 参数:s 字符串首地址。返回值: 成功:读入的字符串。 失败:NULL 例子: 1234567void string_test(void){ char s[100]; if (gets(s) != NULL) { printf("%s\n", s); }} 调用该函数会提示警告是危险的函数,可以使用 fgets()。 1call to 'gets' declared with attribute warning: Using gets() is always unsafe - use fgets() fgets()头文件:#include<stdio.h> 函数原型: 1char * fgets (char *__restrict__ __s, int __n,...
C语言宏笔记详情
宏是C语言中的基石,写 c 程序就必定会用的宏,所有学习宏也是必不可少的。 宏的分类(使用方式): 简单的宏定义(只有宏名):#define DEBUG 简单替换:#define PI 3.1415926 带参数的宏: #define ADD(x,y) ((x) + (y)) // 加法运算 #define SQRT(x) ((x) * (x)) // 平方运算 do {} while(0) 语法在 C 语言 中,使用 do…while 结构来定义宏时,通常是为了确保宏定义中的代码块在使用时可以像一个独立的语句一样被执行。do…while 结构的基本语法如下: 1234#define MACRO_NAME (arguments...)do { /* 宏定义 */} while (0) 1234567891011#include <stdio.h>// 定义一个简单的宏#define PRIVATE_MESSAGE(msg) do {\ ...
C语言动态数组的实现
12345678910struct Dyn_arry_t{ int* array; int capacity; int size;};void dyn_array_test(void);struct Dyn_arry_t dyn_array_init(int* array, int size); 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081#include "dyn_array.h"#include <stdio.h>#include <stdlib.h>#include <string.h>#include "utils.h"/** * @brief 初始化动态数组 * @param array :要初始化的数组 *...
C语言中打印整型数组的函数实现
在这里分享出自己写的,用于打印整型数组的C函数,把函数写到了 utils 文件中,以后可以往里边写一下其他的工具函数。 utils.h12345678910#ifndef _UTILS_H#define _UTILS_H#include <stdio.h>#define Line(message) printf("-------------------- %s --------------------\n", message)void print_array_int(int* arr, int size);#endif /* _UTILS_H */ utils.c12345678910111213141516171819#include "utils.h"#include <stdio.h>void print_array_int(int* arr, int size){ for(int i = 0; i < size; i++) { if (i ==...
LTspice 界面相关翻译
编辑仿真命令对话框瞬态分析 交流分析 直流扫描 噪声分析 直流转换 直流静态工作点 瞬态频率响应分析
FreeRTOS LED闪烁例子
这个例子演示了基于 FreeRTOS 的闪灯程序,这里给出主要代码块。 main.c12345678910void vApplicationTickHook(void){ global_num_1++; if (global_num_1 >= 500) { global_num_1 = 0; // 给 led_task 任务发送通知 xTaskNotifyGive(xTaskGetHandle("led_task")); }} led.c123456789101112/// @brief led FreeRTOS 任务函数/// @param pvParametersvoid led_task(void *pvParameters){ uint32_t ul_notify_value; while (1) { ul_notify_value = ulTaskNotifyTake(pdTRUE, 0); if...
我的Vim配置文件
我的配置文件如下: 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137call plug#begin()" The default plugin directory will be as follows:" - Vim (Linux/macOS): '~/.vim/plugged'" - Vim (Windows):...