Language: C

#include <stdio.h>

#include <string.h>

#define N 100

char a
, b
, str
;

int c

;

int lcs_len(char* a, char* b, int c[]
)

{

int m = strlen(a), n = strlen(b), i, j;

for( i=0; i<=m; i++ )

c[i][0]=0;

for( i=0; i<=n; i++ )

c[0][i]=0;

for( i=1; i<=m; i++ )

{

for( j=1; j<=n; j++ )

{

if (a[i-1]==b[j-1])

c[i][j]=c[i-1][j-1]+1;

else if (c[i-1][j]>=c[i][j-1])

c[i][j]=c[i-1][j];

else

c[i][j]=c[i][j-1];

}

}

return c[m]
;

}

char* build_lcs(char s[], char* a, char* b)

{

int i = strlen(a), j = strlen(b);

int k = lcs_len(a,b,c);

s[k] = '\0';

while( k>0 )

{

if (c[i][j]==c[i-1][j])

i--;

else if (c[i][j]==c[i][j-1])

j--;

else

{

s[--k]=a[i-1];

i--; j--;

}

}

return s;

}

void main()

{

printf("Enter two string (length < %d) :\n",N);

scanf("%s%s",a,b);

printf("LCS=%s\n",build_lcs(str,a,b));

}

Compiler output:
main.c: In function 'lcs_len':
main.c:25:5: error: subscripted value is neither array nor pointer nor vector
   25 | c[i][0]=0;
      |     ^
main.c:29:5: error: subscripted value is neither array nor pointer nor vector
   29 | c[0][i]=0;
      |     ^
main.c:41:5: error: subscripted value is neither array nor pointer nor vector
   41 | c[i][j]=c[i-1][j-1]+1;
      |     ^
main.c:41:15: error: subscripted value is neither array nor pointer nor vector
   41 | c[i][j]=c[i-1][j-1]+1;
      |               ^
main.c:43:16: error: subscripted value is neither array nor pointer nor vector
   43 | else if (c[i-1][j]>=c[i][j-1])
      |                ^
main.c:43:25: error: subscripted value is neither array nor pointer nor vector
   43 | else if (c[i-1][j]>=c[i][j-1])
      |                         ^
main.c:45:5: error: subscripted value is neither array nor pointer nor vector
   45 | c[i][j]=c[i-1][j];
      |     ^
main.c:45:15: error: subscripted value is neither array nor pointer nor vector
   45 | c[i][j]=c[i-1][j];
      |               ^
main.c:49:5: error: subscripted value is neither array nor pointer nor vector
   49 | c[i][j]=c[i][j-1];
      |     ^
main.c:49:13: error: subscripted value is neither array nor pointer nor vector
   49 | c[i][j]=c[i][j-1];
      |             ^
main.c: In function 'build_lcs':
main.c:66:21: error: passing argument 3 of 'lcs_len' makes pointer from integer without a cast [-Wint-conversion]
   66 | int k = lcs_len(a,b,c);
      |                     ^
      |                     |
      |                     int
main.c:16:35: note: expected 'int *' but argument is of type 'int'
   16 | int lcs_len(char* a, char* b, int c[]
      |                               ~~~~^~~
main.c:74:6: error: subscripted value is neither array nor pointer nor vector
   74 | if (c[i][j]==c[i-1][j])
      |      ^
main.c:74:15: error: subscripted value is neither array nor pointer nor vector
   74 | if (c[i][j]==c[i-1][j])
      |               ^
main.c:78:11: error: subscripted value is neither array nor pointer nor vector
   78 | else if (c[i][j]==c[i][j-1])
      |           ^
main.c:78:20: error: subscripted value is neither array nor pointer nor vector
   78 | else if (c[i][j]==c[i][j-1])
      |                    ^
main.c: In function 'main':
main.c:106:29: error: passing argument 1 of 'build_lcs' makes pointer from integer without a cast [-Wint-conversion]
  106 | printf("LCS=%s\n",build_lcs(str,a,b));
      |                             ^~~
      |                             |
      |                             char
main.c:60:22: note: expected 'char *' but argument is of type 'char'
   60 | char* build_lcs(char s[], char* a, char* b)
      |                 ~~~~~^~~
main.c:106:33: error: passing argument 2 of 'build_lcs' makes pointer from integer without a cast [-Wint-conversion]
  106 | printf("LCS=%s\n",build_lcs(str,a,b));
      |                                 ^
      |                                 |
      |                                 char
main.c:60:33: note: expected 'char *' but argument is of type 'char'
   60 | char* build_lcs(char s[], char* a, char* b)
      |                           ~~~~~~^
main.c:106:35: error: passing argument 3 of 'build_lcs' makes pointer from integer without a cast [-Wint-conversion]
  106 | printf("LCS=%s\n",build_lcs(str,a,b));
      |                                   ^
      |                                   |
      |                                   char
main.c:60:42: note: expected 'char *' but argument is of type 'char'
   60 | char* build_lcs(char s[], char* a, char* b)
      |                                    ~~~~~~^