代码: 全选
#include "stdio.h"
void copy_array(int m, int n, double source[m][n], double target[m][n]);
void display_array(int m, int n, double arr[m][n]);
int main(int argc, char const *argv[])
{
int m = 3;
int n = 5;
double source[m][n] = {
{1, 2, 3, 4, 5},
{6, 7, 8, 9, 10},
{11, 12, 13, 14, 15}
};
double target[m][n];
copy_array(m, n, source, target);
printf("array target is:\n");
display_array(m, n, target);
printf("\n");
return 0;
}
void display_array(int m, int n, double arr[m][n])
{
int row;
int col;
for (row = 0; row < m; row++)
{
for (col = 0; col < n; col++)
{
printf("%3.1f", arr[row][col]);
}
printf("\n");
}
}
void copy_array(int m, int n, double source[m][n], double target[m][n])
{
for (int row = 0; row < m; row++)
{
for (int col = 0; col < n; col++)
{
target[row][col] = source[row][col];
}
}
}
/home/drongh/ProgramProjects/c/c primer plus/answer10_8.c:3:46: error: use of parameter outside function body before ‘]’ token
void copy_array(int m, int n, double source[m][n], double target[m][n]);
^
/home/drongh/ProgramProjects/c/c primer plus/answer10_8.c:3:49: error: use of parameter outside function body before ‘]’ token
void copy_array(int m, int n, double source[m][n], double target[m][n]);
^
/home/drongh/ProgramProjects/c/c primer plus/answer10_8.c:3:50: error: expected ‘)’ before ‘,’ token
void copy_array(int m, int n, double source[m][n], double target[m][n]);
^
/home/drongh/ProgramProjects/c/c primer plus/answer10_8.c:3:52: error: expected unqualified-id before ‘double’
void copy_array(int m, int n, double source[m][n], double target[m][n]);
^
/home/drongh/ProgramProjects/c/c primer plus/answer10_8.c:4:46: error: use of parameter outside function body before ‘]’ token
void display_array(int m, int n, double arr[m][n]);
^
/home/drongh/ProgramProjects/c/c primer plus/answer10_8.c:4:49: error: use of parameter outside function body before ‘]’ token
void display_array(int m, int n, double arr[m][n]);
^
/home/drongh/ProgramProjects/c/c primer plus/answer10_8.c:24:46: error: use of parameter outside function body before ‘]’ token
void display_array(int m, int n, double arr[m][n])
^
/home/drongh/ProgramProjects/c/c primer plus/answer10_8.c:24:49: error: use of parameter outside function body before ‘]’ token
void display_array(int m, int n, double arr[m][n])
^
/home/drongh/ProgramProjects/c/c primer plus/answer10_8.c: In function ‘void display_array(...)’:
/home/drongh/ProgramProjects/c/c primer plus/answer10_8.c:28:22: error: ‘m’ was not declared in this scope
for (row = 0; row < m; row++)
^
/home/drongh/ProgramProjects/c/c primer plus/answer10_8.c:30:23: error: ‘n’ was not declared in this scope
for (col = 0; col < n; col++)
^
/home/drongh/ProgramProjects/c/c primer plus/answer10_8.c:32:20: error: ‘arr’ was not declared in this scope
printf("%3.1f", arr[row][col]);
^
/home/drongh/ProgramProjects/c/c primer plus/answer10_8.c: At global scope:
/home/drongh/ProgramProjects/c/c primer plus/answer10_8.c:38:46: error: use of parameter outside function body before ‘]’ token
void copy_array(int m, int n, double source[m][n], double target[m][n])
^
/home/drongh/ProgramProjects/c/c primer plus/answer10_8.c:38:49: error: use of parameter outside function body before ‘]’ token
void copy_array(int m, int n, double source[m][n], double target[m][n])
^
/home/drongh/ProgramProjects/c/c primer plus/answer10_8.c:38:50: error: expected ‘)’ before ‘,’ token
void copy_array(int m, int n, double source[m][n], double target[m][n])
^
/home/drongh/ProgramProjects/c/c primer plus/answer10_8.c:38:52: error: expected unqualified-id before ‘double’
void copy_array(int m, int n, double source[m][n], double target[m][n])