expand函数
来源:互联网 发布:python开发环境搭建 编辑:程序博客网 时间:2024/06/05 17:40
#include <stdio.h>void expand(char * s1, char * s2);int main(){return 0;}/*用strchr实现A-Z a-z的范围判定*/void expand(char * s1, char * s2) {/* 把'-' 和 非'-'作为 分类的标准*//* 其他不满足规则的字符都视为非法,判定出错信息 *//* 对于字符串前和字符串后的*/ static char upper_alph[27] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; static char lower_alph[27] = "abcdefghijklmnopqrstuvwxyz"; static char digits[11] = "0123456789"; char * start, * end, * p; int i = 0; int j = 0; /* Loop through characters in s2 */ while ( s2[i] ) { switch( s2[i] ) { case '-': if ( i == 0 || s2[i+1] == '\0' ) { /* '-' is leading or trailing, so just copy it */ s1[j++] = '-'; ++i; break; } else { /* We have a "range" to extrapolate. Test whether the two operands are part of the same range. If so, store pointers to the first and last characters in the range in start and end, respectively. If not, output and error message and skip this range. */ if ( (start = strchr(upper_alph, s2[i-1])) && (end = strchr(upper_alph, s2[i+1])) ) ; else if ( (start = strchr(lower_alph, s2[i-1])) && (end = strchr(lower_alph, s2[i+1])) ) ; else if ( (start = strchr(digits, s2[i-1])) && (end = strchr(digits, s2[i+1])) ) ; else { /* We have mismatched operands in the range, such as 'a-R', or '3-X', so output an error message, and just copy the range expression. */ fprintf(stderr, "EX3_3: Mismatched operands '%c-%c'\n", s2[i-1], s2[i+1]); s1[j++] = s2[i-1]; s1[j++] = s2[i++]; break; } /* Expand the range */ p = start; while ( p != end ) { s1[j++] = *p; if ( end > start ) ++p; else --p; } s1[j++] = *p; i += 2; } break; default: if ( s2[i+1] == '-' && s2[i+2] != '\0' ) { /* This character is the first operand in a range, so just skip it - the range will be processed in the next iteration of the loop. */ ++i; } else { /* Just a normal character, so copy it */ s1[j++] = s2[i++]; } break; } } s1[j] = s2[i]; /* Don't forget the null character */}
0 0
- expand函数
- matlab ndims 函数 与 expand 函数
- Expand()展开树hRoot列表函数
- tree控件----展开树item的函数----CTreeCtrl::Expand
- Expand Group
- Expression Expand
- Expression Expand
- Expression Expand
- Expression Expand
- Expand命令
- matlab中repmat函数, ndims 函数 与 expand 函数 reshape函数,shiftdim函数和permute函数的用法
- PowerShell Cmdlet Expand
- hippie-expand(zz)
- Expand Status bar
- autosys expand file name
- expand解压缩cab文件
- expand解压缩cab文件
- see Macro expand magic
- 关于数据库中的主键和外键以及unique
- poj 1088 滑雪 (状态压缩DP)
- Eclipse快捷键大全
- 第三次实现Logistic Regression(c++)_再尝试
- Win7旗舰版中的IIS配置asp.net的运行环境
- expand函数
- win7(64位)下的某些文件,用VB6开发的程序无法判断是否存在
- easyUI 行显示嵌套对象的方法
- 先天之易后天之易
- Combobox控件出现SelectedValue的值为“System.Data.DataRowView”
- (实验)Podfile的target与link_with
- A drop of Performance testing-SQL Optimization 2
- datagridview右键选中一行
- 奇偶數