当前位置:网站首页>Tips for formatting code indentation
Tips for formatting code indentation
2022-08-05 06:44:00 【ProfSnail】
In recent days, I have often been in the Q&A section to answer questions, and found a little problem.
The code that some friends put up when they ask questions is not indented; or the programming format is not very beautiful, and they are often fascinated by it.
The brother who asked the question quickly put a piece of code because he was in a hurry.
I am here to help him answer questions, looking at the code, I am quite anxious.Today, I accidentally discovered a piece of unindented code, just to share a wave of questions.
I simply take a small program in C language that I have helped deal with in the past two days as an example.I changed it to unindented format.
BTree createTree(char s[]) {BTNode *p;BTNode *rt;BTNode *lchild, *rchild, parent;stack S;p = (BTNode * )malloc(sizeof(BTNode));p->lchild = NULL;p->rchild = NULL;p->data = s[0];S.push§;rt = p;for(int i = 1; s[i] != '\0';i++){if('A' <= s[i] && s[i] <= 'Z') {p = (Node ) malloc(sizeof(Node));p->data = s[i];p->lchild = NULL;p->rchild = NULL;S.pop();S.push§;}if(s[i] == '(') {S.push(NULL);}if(s[i] == ',') {S.push(NULL);}if(s[i] == ')') {rchild = S.top();S.pop();lchild =S.top();S.pop();parent = S.top();S.pop();parent->lchild = lchild;parent->rchild = rchild;S.push(parent);}}returnrt;}
This code doesn't really want to be bothered by looking at it, but let's think about it.The best way is to copy this code and paste it into Visual Studio.
But for all the code without blank lines, VS can't handle it.It needs to be processed with Sublime Text first.
Sublime Text Ctrl + H to bring up the replacement interface.Search for semicolons and replace all semicolons with a semicolon plus a newline (the newline can be typed out with Ctrl+Enter).
Next, copy the code in SublimeText into VisualStudio, and VisualStudio will help with indentation and parentheses.
You're done!
How do you deal with this situation?Welcome to discuss~
边栏推荐
- 自营商城提高用户留存小技巧,商城对接小游戏分享
- ES2020新特性
- 媒体查询、rem移动端适配
- Take you in-depth understanding of cookies
- Does flink cdc currently support Gauss database sources?
- DevOps-了解学习
- In-depth analysis if according to data authority @datascope (annotation + AOP + dynamic sql splicing) [step by step, with analysis process]
- D46_Force applied to rigid body
- D45_Camera assembly Camera
- el-autocomplete use
猜你喜欢
随机推荐
ALC experiment
Passing parameters in multiple threads
获取预训练模型的网络输入尺寸
多行文本省略
LaTeX 图片加标题 文本分栏自动换行
多用户商城多商户B2B2C拼团砍价秒杀支持小程序H5+APP全开源
product learning materials
selenium learning
网络协议基础-学习笔记
Four ways to obtain Class objects through reflection
错误记录集锦(遇到则记下)
System basics - study notes (some command records)
Q 2020, the latest senior interview Laya soul, do you know?
白鹭egret添加新页面教程,如何添加新页面
The 25 best free games on mobile in 2020
LeetCode practice and self-comprehension record (1)
原生JS带你了解数组方法实现及使用
cs231n学习记录
Successful indie developers deal with failure & imposters
Nacos集群搭建