因为是新手,很多不懂!求点拨!
#include <stdio.h>#include <stdlib.h>
#include <string.h>
#define MAX_COLS 20
#define MAX_INPUT 1000
int read_column_numbers( int columns[], int max);
int main(void)
{
int n_columns;
int columns[MAX_COLS];
char input[MAX_INPUT];
char output[MAX_INPUT];
n_columns=read_column_numbers(columns,MAX_COLS);
while (gets(input)!=NULL)
{
printf("Original input:%s\n",input);
printf("Rearranged line:%s\n",output);
}
return EXIT_SUCCESS;
}
int read_column_numbers(int columns[], int max)
{
int num =0;
int ch;
while ( num<max && scanf ("%d",&columns[num] )==1
&& columns[num] >=0)
num+=1;
if (num %2 != 0){
puts ("Last column number is not pairded.");
exit ( EXIT_FAILURE);
}
while( (ch=getchar())!='EOF' && ch!='\n')
;
return num;
}
void rearrange( char *output, char const * input,
int n_columns, int const columns [])
{
int col;
int output_col;
int let;
let = strlen(input);
output_col = 0;
for( col =0; col< n_columns; col +=2)(
if (col =0 ;col=n_columns;col +=2){
int nchars = columns[col + 1]-columns[col]+1;
if (columns [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+columns[col],
nchars);
output_col +=nchars;
} output['output_col'] ='\0';
}
--------------------Configuration: 1 - Win32 Debug--------------------
Compiling...
1.c
C:\Users\Administrator\Desktop\1.c(51) : error C2059: syntax error : 'if'
C:\Users\Administrator\Desktop\1.c(51) : error C2143: syntax error : missing ';' before ')'
C:\Users\Administrator\Desktop\1.c(53) : error C2065: 'len' : undeclared identifier
C:\Users\Administrator\Desktop\1.c(55) : error C2043: illegal break
C:\Users\Administrator\Desktop\1.c(56) : error C2065: 'nchars' : undeclared identifier
C:\Users\Administrator\Desktop\1.c(61) : error C2015: too many characters in constant
C:\Users\Administrator\Desktop\1.c(61) : error C2466: cannot allocate an array of constant size 0
C:\Users\Administrator\Desktop\1.c(61) : error C2075: 'output' : array initialization needs curly braces
C:\Users\Administrator\Desktop\1.c(62) : error C2059: syntax error : '}'
执行 cl.exe 时出错.
1.obj - 1 error(s), 0 warning(s)