声明终止不正确。 [英] Declaration terminated incorrectly .

查看:101
本文介绍了声明终止不正确。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

宣言终止不正确..请尽快帮助



我尝试过:



Declaration terminated incorrectly .. Please help as fast as possible

What I have tried:

/* Dynamic Programming C/C++ implementation of LCS problem */
#include<stdio.h>
#include<stdlib.h>
  
int max(int a, int b);
  
/* Returns length of LCS for X[0..m-1], Y[0..n-1] */
int lcs( char *X, char *Y, int m, int n )
{
   int L[m+1][n+1];
   int i, j;
  
   /* Following steps build L[m+1][n+1] in bottom up fashion. Note 
      that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */
   for (i=0; i<=m; i++)
   {
     for (j=0; j<=n; j++)
     {
       if (i == 0 || j == 0)
         L[i][j] = 0;
  
       else if (X[i-1] == Y[j-1])
         L[i][j] = L[i-1][j-1] + 1;
  
       else
         L[i][j] = max(L[i-1][j], L[i][j-1]);
     }
   }
    
   /* L[m][n] contains length of LCS for X[0..n-1] and Y[0..m-1] */
   return L[m][n];
}
  
/* Utility function to get max of 2 integers */
int max(int a, int b)
{
    return (a > b)? a : b;
}
  
/* Driver program to test above function */
int main()
{
  char X[] = "AGGTAB";
  char Y[] = "GXTXAYB";
  
  int m = strlen(X);
  int n = strlen(Y);
  
  printf("Length of LCS is %d\n", lcs( X, Y, m, n ) );
 
  return 0;
}




line 5 declaration terminated incorrectly
line 10 constant expression required
line 11 constant expression required
line 35 declaration terminated incorrectly(the function just before int main())

推荐答案

处理你的错误订购:



第5行声明未正确终止

我没有收到此错误。我不熟悉Turbo C ++ compliler,但可能是你的函数与std :: max冲突的情况。尝试将您的函数重命名为myMax。还要确保该行末尾没有隐形字符。



需要第10行常量表达式

第11行需要常量表达式


C ++在声明数组时不允许使用变量,因此以下行是非法的:

To deal with your errors in order:

line 5 declaration terminated incorrectly
I am not getting this error. I am not familiar with the Turbo C++ compliler but it may be the case that your function is clashing with std::max. Try renaming your function to myMax. Also make sure that there are no "invisible" characters at the end of that line.

line 10 constant expression required
line 11 constant expression required

C++ does not allow variables when declaring arrays so the following line is illegal:
int L[m+1][n+1];



您可以使用常量,但更好的选择可能是使用 vector [ ^ ]



第35行声明未正确终止(函数就在int main()之前)

这是指你的 max 函数 - 试试我上面建议的重命名。




You can use constants but a better option would probably be to use a vector[^]

line 35 declaration terminated incorrectly(the function just before int main())
This is referring to your max function again - try the rename I suggested above.

引用:

你可以运行程序并将输出邮寄给我吗?我真的无法纠正它

can you please run the program and mail me the output? i really cannot correct it

没有。这是你的功课,不是我的。你需要的是一点点坚持不懈的努力。或者你总是可以回到你复制这段代码的地方并复制那里发布的其他一个选项...但你不会那么学习。

No. This is your homework, not mine. A bit of perseverance is all that is required on your part. Alternatively you could always go back to where you copied this code from and copy one of the other options posted there... but you won't learn much that way.


这篇关于声明终止不正确。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆