|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_COLS 20
#define MAX_INPUT 1000
int read_column_members(int column,int max);
void rearrange(char *output,char const *input,int n_column,int const column[]);
int main()
{
int n_column;
int column[MAX_COLS];
char input[MAX_INPUT];
char output[MAX_INPUT];
n_column = read_column_members(column,MAX_COLS);
while(gets(input) != NULL)
{
printf("Original input:%s\n",input);
rearrange(output,input,n_column,column);
printf("Rearranged line:%s\n",output);
}
return EXIT_SUCCESS;
}
int read_column_members(int column,int max)
{
int num = 0;
int ch;
while(num < max && scanf("%d",&column[num]) == 1 && column[num] >= 0)
{
num += 1;
if(num % 2 !=0)
{
puts("Last column number is not paired");
exit(EXIT_FAILURE);
}
while((ch = getchar()) != EOF && ch != '\n')
;
return num;
}
}
void rearrange(char *output,char const *input,int n_column,int const column[])
{
int col;
int output_col;
int len;
len = strlen(input);
output_col = 0;
for(col=0;col<n_column;col+=2)
{
int nchars = column[col+1] - column[col] + 1;
if(column[col] >= len || output_col = MAX_INPUT - 1)
break;
if(output_col + nchars > MAX_INPUT - 1)
{
nchars = MAX_INPUT - output_col - 1;
}
strncpy(output + output_col,input + column[col],nchars);
output_col += nchars;
}
output[output_col] = '\0';
}
--------------------Configuration: 12 - Win32 Debug--------------------
Compiling...
12.cpp
F:\测试代码\12.cpp(18) : error C2664: 'read_column_members' : cannot convert parameter 1 from 'int [20]' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
F:\测试代码\12.cpp(34) : error C2109: subscript requires array or pointer type
F:\测试代码\12.cpp(34) : error C2102: '&' requires l-value
F:\测试代码\12.cpp(34) : error C2109: subscript requires array or pointer type
F:\测试代码\12.cpp(34) : fatal error C1903: unable to recover from previous error(s); stopping compilation
执行 cl.exe 时出错.
12.obj - 1 error(s), 0 warning(s)
|
|