资源简介
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 */
#ifdef R
int read_column_numbers( int columns[] int max );
void rearrange( char *output char const *input
int n_columns int const columns[] );
#endif
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 )
{ /*-=============11================-*/
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
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 11599067 2006-10-13 13:39 C和指针\C和指针.pdf
文件 3336 2008-02-08 08:58 C和指针\programs\ch1\rearrang.c
文件 10052 2008-02-02 16:07 C和指针\programs\ch1\rearrang.exe
文件 986 2008-02-02 16:07 C和指针\programs\ch1\rearrang.obj
文件 10052 2008-02-02 16:07 C和指针\programs\ch1\tempfile.exe
目录 0 2008-10-31 11:48 C和指针\programs\ch1
文件 386 1997-06-20 11:45 C和指针\programs\ch11\alloc.c
文件 234 1997-06-20 11:45 C和指针\programs\ch11\alloc.h
文件 233 1997-06-20 11:45 C和指针\programs\ch11\a_client.c
文件 1056 1997-06-20 11:45 C和指针\programs\ch11\invcreat.c
文件 464 1997-06-20 11:45 C和指针\programs\ch11\invdelet.c
文件 595 1997-06-20 11:45 C和指针\programs\ch11\inventor.h
文件 1311 1997-06-20 11:45 C和指针\programs\ch11\sort.c
文件 614 1997-06-20 11:45 C和指针\programs\ch11\strdup.c
目录 0 2008-10-31 11:48 C和指针\programs\ch11
文件 1792 1997-06-20 11:45 C和指针\programs\ch12\dll_ins1.c
文件 692 1997-06-20 11:45 C和指针\programs\ch12\dll_ins2.c
文件 284 1997-06-20 11:45 C和指针\programs\ch12\dll_ins3.c
文件 1282 1997-06-20 11:46 C和指针\programs\ch12\dll_ins4.c
文件 187 1997-06-20 11:45 C和指针\programs\ch12\dll_ins5.c
文件 86 1997-06-20 11:45 C和指针\programs\ch12\dll_node.h
文件 927 1997-06-20 11:46 C和指针\programs\ch12\insert1.c
文件 1106 1997-06-20 11:46 C和指针\programs\ch12\insert2.c
文件 953 1997-06-20 11:46 C和指针\programs\ch12\insert3.c
文件 67 1997-06-20 11:45 C和指针\programs\ch12\sll_node.h
目录 0 2008-10-31 11:48 C和指针\programs\ch12
文件 331 1997-06-20 11:45 C和指针\programs\ch13\btoa.c
文件 879 1997-06-20 11:45 C和指针\programs\ch13\cmd_line.c
文件 340 1997-06-20 11:45 C和指针\programs\ch13\echo.c
文件 205 1997-06-20 11:45 C和指针\programs\ch13\mystery.c
............此处省略111个文件信息
- 上一篇:LTE原理及系统架构
- 下一篇:ExtJs商场VIP消费查询系统北风网源码完全版
评论
共有 条评论