Click here to Skip to main content
15,889,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Declaration terminated incorrectly .. Please help as fast as possible

What I have tried:

C++
/* 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())
Posted
Updated 2-Apr-16 3:04am
v5
Comments
CHill60 2-Apr-16 8:31am    
If you want a fast response try giving the full details of the error - including which line was highlightedApologies - found it at the bottom of the code
Member 11838184 2-Apr-16 8:38am    
please answer?? @chill60
CHill60 2-Apr-16 8:41am    
What version of the compiler are you using and is this C or C++? I don't get any error on that function prototype
Member 11838184 2-Apr-16 8:42am    
i am using turboo c++ 3.2
and this is c.
Member 11838184 2-Apr-16 8:43am    
can u please give me the correct link from where to download the compiler you have?

1 solution

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];

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.

Quote:
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.
 
Share this answer
 
Comments
[no name] 2-Apr-16 9:22am    
A 5 for your help.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900