求大神帮忙!(最长公共子序列)
#include <stdlib.h>#include <stdio.h>
void LCSLength(int m, int n, char *x, char *y, int **c)
{
int i, j;
//初始化二维数组
for (i = 1; i <= m; i++)
{
c = 0;
printf("%d ", c);
}
for (i = 1; i <= n; i++)
c = 0;
//逐行填充二维数组
for (i = 1; i <= m; i++)
for (j = 1; j <= n; j++)
{
if (x == y)
c = c + 1;
else if
(c >= c) c = c;
else
c = c;
}
for (i = 0; i <= m; i++)
{
for (j = 0; j <= n; j++)
{
printf("%d ", c);
}
printf("\n");
}
}
int main()
{
char a[] = { 1, 3, 4, 5, 6,7, 7, 8,'\0' };
char b[] = { 3, 5, 7, 4, 8,6,7,8,2,'\0' };
char *x = &a;
char *y = &b;
int m = sizeof(a) - 1; //X元素序列的个数
int n = sizeof(b) - 1;//Y元素序列的个数
//为二维数组申请动态空间,m为行数,n为列数
int **c = (int **)malloc(sizeof(int *) * m); //分配行数
for (int i = 0; i < m; i++) //为每一行分配内存
{
c = (int*)malloc(sizeof(int)*n);
}
printf("-------\n");
LCSLength(m, n, x, y, c);
printf("-------\n");
printf("%d\n", c);
}
报错如图 void LCSLength()函数数组初始化的时候越界了
页:
[1]