代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
C
】
通用排序程序
作者:
DDT
/ 发布于
2013/1/8
/
499
/* * SORT - reads line of a file and sorts them in order * Copyright 1995 Jim Lynch * * Adapted for ReactOS * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <stdlib.h> #include <stdio.h> #include <string.h> #include <malloc.h> #define MAXRECORDS 65536 /* maximum number of records that can be * sorted */ #define MAXLEN 4095 /* maximum record length */ int rev; /* reverse flag */ int help; /* help flag */ int sortcol; /* sort column */ int err = 0; /* error counter */ int cmpr(const void *a, const void *b) { char *A, *B; A = *(char **) a; B = *(char **) b; if (sortcol > 0) { if (strlen(A) > sortcol) A += sortcol; else A = ""; if (strlen(B) > sortcol) B += sortcol; else B = ""; } if (!rev) return strcmp(A, B); else return strcmp(B, A); } void usage(void) { fputs("SORT\n", stderr); fputs("Sorts input and writes output to a file, console or a device.\n", stderr); if (err) fputs("Invalid parameter\n", stderr); fputs(" SORT [options] < [drive:1][path1]file1 > [drive2:][path2]file2\n", stderr); fputs(" Command | SORT [options] > [drive:][path]file\n", stderr); fputs(" Options:\n", stderr); fputs(" /R Reverse order\n", stderr); fputs(" /+n Start sorting with column n\n", stderr); fputs(" /? Help\n", stderr); } int main(int argc, char **argv) { char temp[MAXLEN + 1]; char **list; char *cp; /* option character pointer */ int nr; int i; sortcol = 0; rev = 0; while (--argc) { if (*(cp = *++argv) == '/') { switch (cp[1]) { case 'R': case 'r': rev = 1; break; case '?': case 'h': case 'H': help = 1; break; case '+': sortcol = atoi(cp + 1); if (sortcol) sortcol--; break; default: err++; } } } if (err || help) { usage(); exit(1); } list = (char **) malloc(MAXRECORDS * sizeof(char *)); if (list == NULL) { fputs("SORT: Insufficient memory\n", stderr); exit(3); } for (nr = 0; nr < MAXRECORDS; nr++) { if (fgets(temp, MAXLEN, stdin) == NULL) break; if(strlen(temp)) temp[strlen(temp)-1]='\0'; list[nr] = (char *) malloc(strlen(temp) + 1); if (list[nr] == NULL) { fputs("SORT: Insufficient memory\n", stderr); exit(3); } strcpy(list[nr], temp); } if (nr == MAXRECORDS) { fputs("SORT: number of records exceeds maximum\n", stderr); exit(4); } qsort((void *) list, nr, sizeof(char *), cmpr); for (i = 0; i < nr; i++) { fputs(list[i], stdout); fputs("\n",stdout); } return 0; } /* EOF */
试试其它关键字
排序
同语言下
.
获取手机通讯录 iOS去除数字以外的所有字符
.
异步加载音乐等资源
.
交通罚单管理系统
.
freemark实现,简单的替换
.
计算斐波那契数列
.
base64解码 包括解码长度
.
图像显示
.
冒泡排序
.
输入十进制数,输出指定进制
.
链式栈
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
DDT
贡献的其它代码
(
160
)
.
Oracle统计表的数据行和数据块信息
.
html标签闭合检测与修复
.
Powershell日期计算
.
Powershell的Base64编解码
.
Powershell并行循环
.
Powershell目录中搜索文本
.
Powershell枚举远程机器上的本地权限组
.
VBScript解析csv文件
.
快速排序之Powershell
.
批处理输出格式化时间字符串
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3