连接控制:学习stty

终端是人们用来和Unix进程进行通信的设备。终端拥有一个可以让进程读取字符的键盘和可让进程发送字符的显示器。终端是一个设备,所以它在目录树中表现为一个特殊的文件,通常在/dev这个目录中。

进程和终端间的数据传输和数据处理由终端驱动程序负责,终端驱动程序时内核的一部分。该内核代码提供缓冲、编辑、和数据转换。程序可以通过tcgetattr和tcsetattr查看和修改驱动程序的设置。

tty也是一个Unix/Linux命令,用来给出当前终端设备的名称。stty命令让用户读取和修改终端驱动程序的位置。

终端是一种字符型设备,它有多种类型,通常使用tty来简称各种类型的终端设备。

每个加载到......

实现pwd命令

本文参考Unix linux编程实践教程,完成编写pwd命令,并介绍相关核心知识点。

命令pwd用来显示到达当前目录的路径。例如:

root@ubuntu:~/uup/experiments# pwd

/root/uup/experiments

root@ubuntu:~/uup/experiments#

pwd命令的实现思路:

1.得到当前目录.的i节点号

2.然后改变当前目录为父目录

3.与查询出来的目录信息通过i节点号比较

4.重复此过程

由于在根目录. 和..的i节点号相同,因此递归终止的条件是到达根目录。

#include <stdio.h>......

[LeetCode C实现]832. Flipping an Image

Given a binary matrix A, we want to flip the image horizontally, then invert it, and return the resulting image.

To flip an image horizontally means that each row of the image is reversed. For example, flipping [1, 1, 0] horizontally results in [0, 1, 1].

To invert an image means that each ......

[LeetCode C实现]762. Prime Number of Set Bits in Binary Representation

Given two integers L and R, find the count of numbers in the range L, R having a prime number of set bits in their binary representation.

(Recall that the number of set bits an integer has is the number of 1s present when written in binary. For example, 21 written in binary is 10101 which has 3 ......

[LeetCode C实现] 821. Shortest Distance to a Character

Given a string S and a character C, return an array of integers representing the shortest distance from the character C in the string.

Example 1:

Input: S = "loveleetcode", C = 'e'

Output:

Note:

S string length is in [1, 10000].

C is a single character, and guara......

[LeetCode C 实现]653. Two Sum IV - Input is a BST

Given a Binary Search Tree and a target number, return true if there exist two elements in the BST such that their sum is equal to the given target.

Example 1:

Input:

5

/ \

3 6

/ \ \

2 4 7

Target = 9

Output: True

Example 2:

Input:

5

/ \

3 6

/ \ \

2 4 7

......

[LeetCode C实现] 167. Two Sum II - Input array is sorted

Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.

The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2.

Note:

Your re......

[LeetCode C实现]371. Sum of Two Integers

Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.

Example:

Given a = 1 and b = 2, return 3.

Credits:

Special thanks to @fujiaozhu for adding this problem and creating all test cases.

第一次在leetcode上看到反对票比赞成票多这么多的题目。

C实现代码如下:

int getSum(int a,......

[LeetCode C 实现]538. Convert BST to Greater Tree

Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in BST.

Input: The root of a Binary Search Tree like this:

5

/ \

2 13

Output: The root of a Greater Tree ......

[LeetCode C实现]230. Kth Smallest Element in a BST

Given a binary search tree, write a function kthSmallest to find the kth smallest element in it.

Note:

You may assume k is always valid, 1 ≤ k ≤ BST's total elements.

Example 1:

Input: root = [3,1,4,null,2], k = 1

Output: 1

Example 2:

Input: root = [5,3,6,2,4,null,null,1], k ......