当前位置:网站首页>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~
边栏推荐
猜你喜欢
随机推荐
BIO, NIO, AIO practical study notes (easy to understand theory)
云计算基础-学习笔记
【FAQ】CCAPI兼容EOS相机列表(2022年8月 更新)
el-autocomplete使用
白鹭egret添加新页面教程,如何添加新页面
vs2017关于函数命名方面的注意事项
Mina disconnects and reconnects
Drools规则引擎快速入门(一)
numpy.random使用文档
Cloud Computing Basics - Study Notes
Q 2020, the latest senior interview Laya soul, do you know?
H5 的浏览器存储
设置文本向两边居中展示
单片机期末复习大题
数组&的运算
【考研结束第一天,过于空虚,想对自己进行总结一下】
LaTeX image captioning text column automatic line wrapping
LeetCode刷题记录(2)
网络排错基础-学习笔记
ALC experiment









