资源简介
c和指针 课本源代码及课后答案[完整版]c和指针 课本源代码及课后答案[完整版]c和指针 课本源代码及课后答案[完整版]c和指针 课本源代码及课后答案[完整版]c和指针 课本源代码及课后答案[完整版]c和指针 课本源代码及课后答案[完整版]c和指针 课本源代码及课后答案[完整版]c和指针 课本源代码及课后答案[完整版]c和指针 课本源代码及课后答案[完整版]c和指针 课本源代码及课后答案[完整版]c和指针 课本源代码及课后答案[完整版]c和指针 课本源代码及课后答案[完整版]c和指针 课本源代码及课后答案[完整版]c和指针 课本源代码及课后答案[完整版]c和指针 课本源代码及课后答案[完整版]

代码片段和文件信息
/*
** This program reads input lines from the standard input and prints
** each input line followed by just some portions of the lines to
** the standard output.
**
** The first input is a list of column numbers which ends with a
** negative number. The column numbers are paired and specify
** ranges of columns from the input line that are to be printed.
** For example 0 3 10 12 -1 indicates that only columns 0 through 3
** and columns 10 through 12 will be printed.
*/
#include
#include
#include
#define MAX_COLS 20 /* max # of columns to process */
#define MAX_INPUT 1000 /* max len of input & output lines */
int read_column_numbers( int columns[] int max );
void rearrange( char *output char const *input
int n_columns int const columns[] );
int
main( void )
{
int n_columns; /* # of columns to process */
int columns[MAX_COLS]; /* the columns to process */
char input[MAX_INPUT]; /* array for input line */
char output[MAX_INPUT]; /* array for output line */
/*
** Read the list of column numbers
*/
n_columns = read_column_numbers( columns MAX_COLS );
/*
** Read process and print the remaining lines of input.
*/
while( gets( input ) != NULL ){
printf( “Original input : %s\n“ input );
rearrange( output input n_columns columns );
printf( “Rearranged line: %s\n“ output );
}
return EXIT_SUCCESS;
}
/*
** Read the list of column numbers ignoring any beyond the specified
** maximum.
*/
int
read_column_numbers( int columns[] int max )
{
int num = 0;
int ch;
/*
** Get the numbers stopping at eof or when a number is < 0.
*/
while( num < max && scanf( “%d“ &columns[num] ) == 1
&& columns[num] >= 0 )
num += 1;
/*
** Make sure we have an even number of inputs as they are
** supposed to be paired.
*/
if( num % 2 != 0 ){
puts( “Last column number is not paired.“ );
exit( EXIT_FAILURE );
}
/*
** Discard the rest of the line that contained the final
** number.
*/
while( (ch = getchar()) != EOF && ch != ‘\n‘ )
;
return num;
}
/*
** Process a line of input by concatenating the characters from
** the indicated columns. The output line is then NUL terminated.
*/
void
rearrange( char *output char const *input
int n_columns int const columns[] )
{
int col; /* subscript for columns array */
int output_col; /* output column counter */
int len; /* length of input line */
len = strlen( input );
output_col = 0;
/*
** Process each pair of column numbers.
*/
for( col = 0; col < n_columns; col += 2 ){
int nchars = columns[col + 1] - columns[col] + 1;
/*
** If the input line isn‘t this long or the output
** array is full we‘re done.
*/
if( columns[col] >= len ||
output_col == MAX_INPUT - 1 )
break;
/*
** If there isn‘t room in the output array only copy
** what will fit.
*/
if( output_col + ncha
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3242 1997-06-20 11:45 c和指针代码及答案\ch1\rearrang.c
文件 386 1997-06-20 11:45 c和指针代码及答案\ch11\alloc.c
文件 234 1997-06-20 11:45 c和指针代码及答案\ch11\alloc.h
文件 233 1997-06-20 11:45 c和指针代码及答案\ch11\a_client.c
文件 1056 1997-06-20 11:45 c和指针代码及答案\ch11\invcreat.c
文件 464 1997-06-20 11:45 c和指针代码及答案\ch11\invdelet.c
文件 595 1997-06-20 11:45 c和指针代码及答案\ch11\inventor.h
文件 1311 1997-06-20 11:45 c和指针代码及答案\ch11\sort.c
文件 614 1997-06-20 11:45 c和指针代码及答案\ch11\strdup.c
文件 1792 1997-06-20 11:45 c和指针代码及答案\ch12\dll_ins1.c
文件 692 1997-06-20 11:45 c和指针代码及答案\ch12\dll_ins2.c
文件 284 1997-06-20 11:45 c和指针代码及答案\ch12\dll_ins3.c
文件 1282 1997-06-20 11:46 c和指针代码及答案\ch12\dll_ins4.c
文件 187 1997-06-20 11:45 c和指针代码及答案\ch12\dll_ins5.c
文件 86 1997-06-20 11:45 c和指针代码及答案\ch12\dll_node.h
文件 927 1997-06-20 11:46 c和指针代码及答案\ch12\insert1.c
文件 1106 1997-06-20 11:46 c和指针代码及答案\ch12\insert2.c
文件 953 1997-06-20 11:46 c和指针代码及答案\ch12\insert3.c
文件 67 1997-06-20 11:45 c和指针代码及答案\ch12\sll_node.h
文件 331 1997-06-20 11:45 c和指针代码及答案\ch13\btoa.c
文件 879 1997-06-20 11:45 c和指针代码及答案\ch13\cmd_line.c
文件 340 1997-06-20 11:45 c和指针代码及答案\ch13\echo.c
文件 205 1997-06-20 11:45 c和指针代码及答案\ch13\mystery.c
文件 417 1997-06-20 11:45 c和指针代码及答案\ch13\node.h
文件 532 1997-06-20 11:45 c和指针代码及答案\ch13\search.c
文件 492 1997-06-20 11:45 c和指针代码及答案\ch15\char_int.c
文件 332 1997-06-20 11:45 c和指针代码及答案\ch15\copyline.c
文件 673 1997-06-20 11:45 c和指针代码及答案\ch15\open_cls.c
文件 454 1997-06-20 11:48 c和指针代码及答案\ch15\rd_rand.c
文件 491 1997-06-20 11:45 c和指针代码及答案\ch15\scanf1.c
............此处省略102个文件信息
- 上一篇:单片机开发板protues仿真图
- 下一篇:ZCU102的完整PYNQ鏡像
相关资源
- CVSNT 完整覆盖版防TortoiseCVS中文乱码
- BCG帮助手册,完整版_修正
- 交通咨询模拟系统完整代码
- 网上拍卖系统完整源代码
- STM32F103 串口程序(完整版)
- 可拖拽的甘特图控件(完整)
- 武汉理工大学 单片机课程设计 16*16点
- 完整的项目案例
- 完整版家庭在线记账理财管理系统
- 国际象棋c 完整版
- 一个比较完整的开源cad 图形程序
- STM32F103 CC2500完整驱动(模拟SPI)
- 30秒倒计时器完整版下载
- 操作系统课程设计完整版
- 这是一个套完整的综合布线系统方案
- 学生成绩管理系统C 源码(很完整)
- 捆绑源码发布 捆绑软件源码 完整版
- 基于Petri网的工作流(完整的原创源代
- 典当综合业务管理系统(完整版)
- 《原子物理学》高教 杨福家 完整版课
- DOS命令大全(完整版)
- SX126x_LORA驱动程序(包含完整的工程文
- 计算机操作系统(第四版)汤小丹课
- xlrd-1.2.0完整包
- ARM64 完整指令集,学习必备
- 完整的雷达系统仿真程序
- CS起源方框透视本
- 微信小程序驾照考试题库demo完整
- RTL8188 USB无线网卡模块完整方案
- 取名软件完整版
评论
共有 条评论