鱼C论坛

 找回密码
 立即注册
查看: 3556|回复: 0

C和指针 这本书的一个题报错 帮忙看下

[复制链接]
发表于 2012-11-19 20:41:11 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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)
小甲鱼最新课程 -> https://ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-11-16 10:25

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表