英文排版系统C语言实现
英文排版系统C语言实现代码: #include #include #include void route(char Text[],int *start,int *end,int column); void output(char cpy[],int column); int countspace(char cpy[]); int main() { system("color 0B"); Menu(); int start,end,column,length; int i; char Text[10000],ch; printf("nPlease input or copy the text you want to transform:nn"); gets(Text); printf("nnPlease input the column(column>=25):"); scanf("%d",&column); system("cls"); printf("n"); printf("Transformed text:nn"); start=0; end=column-1; length=strlen(Text); if(length { printf("%s",Text); return 0; } while(end { route(Text,&start,&end,column); } for(i=start; i { printf("%c",Text[i]); } printf("nnInput 'c' to continue or input ESC to quit!"); while(1) { ch=getch(); if(ch=='c') { getchar(); system("cls"); return main(); } else if(ch==27) { return 0; } else { ; } } } void route(char Text[],int column) { int i,j; char cpy[500]=""; while(Text[*end]!=' '&&Text[*end]!=','&&Text[*end]!='!'&&Text[*end]!='.')//代表每行最后一个字符是字母 *end=*end-1; if(Text[*end]==' ') { for(i=*start,j=0; i<*end; i++,j++) { cpy[j]=Text[i]; } } else for(i=*start,j=0;i<=*end;i++,j++) cpy[j]=Text[i]; *start=*end+1; *end=*start+column; output(cpy,column); } void output(char cpy[],int column) { char strout[500]=""; int i,j=0; int spacecount,difference,space0,spacex; spacecount=countspace(cpy); difference=column-strlen(cpy); space0=(column-strlen(cpy))/spacecount; spacex=(column-strlen(cpy))%spacecount; for(i=0; i { strout[i]=' '; } if(difference>0) { for(i=0,j=0; i { if(cpy[i]==' ') { j+=space0; if(spacex>0) { j++; spacex--; } } strout[j]=cpy[i]; j++; } printf("%sn",strout); } else { printf("%sn",cpy); } } int countspace(char cpy[]) { int i,sum=0; for(i=0; i { if(cpy[i]==' ') { sum++; } } return sum; } void Menu() { char ch; printf(" 【【English text form transformation system】】n"); printf(" =============================================================="); printf("n 1.Start"); printf("n 2.Quitn"); printf(" =============================================================="); printf("nnInput the number you want to operate:"); while(1) { ch=getch(); if(ch=='1') { system("cls"); return; } else if(ch=='2') { exit(0); } else { ; } } } 备注: 大家在开始运行程序后,粘贴大量文本的时候注意一下,因为在codeblocks的黑框环境下它会卡,所以就点黑框上方的白色边界里面的编辑—>粘贴 即可粘贴入大量待排版的文本了O(∩_∩)O。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- 【tips】flash,字符设备与块设备 I/O 操作的不同
- 尝试将数组存储在NSUserDefaults Swift中时,获取“不执行me
- oracle-sqldeveloper – 如何更改Oracle SQL Developer / O
- npm run-script flow无效
- c# – 创建安装项目时如何使用最终的{project} .exe.config
- Unity(七):使用场景Ⅲ:用于依赖注入(下)
- ruby-on-rails – 当用作回调时,Ruby块中的`return`和`brea
- iphone – 如何在xcode中创建DropDown?
- SBJson (aka json-framework)
- NSLog有一个Swift替代(@“%s”,__PRETTY_FUNCTION__)