I have two files which goes like this :

FILE A is :

J5
J15
J25
J30
J35

and FILE B is:

J0 23 56
J5 24 58
J10 26 60
J15 29 63
J20 31 36
J25 23 32
J30 51 14
J35 34 21
J40 46 12

The problem is that I have to check FILE A with FILE B for its contents and copy the values of Jth items in a new file like this : ( FILE C ) :

J5 24 58
J15 29 63
J25 23 32
J30 51 14
J35 34 21

I am new to programming and a such finding it very difficult to do this. Thanks.

post what you have done so that we can help you. I would probably read the contents of File B into an array in memory then search that array for each line in File A.

I am making this code but it gives error.
the compiler says : syntax error before printf at line no 9.
any help in this regard ?

#include <stdio.h>
#include <stdlib.h>
int main()
FILE *fp1 ,*fp2;
int i,j;
char A[i][j],B[i][j],x[i][j];
char file1[1024],file2[1024];
printf(" Enter file1: ",file1);
gets(file1);
printf("Enter file2: ",file2);
gets(file2);
fp1=fopen(file1,"r");
if ( fp1 == NULL )
    {
        printf("Cannot open %s for reading \n", file1 );
        exit(1);
     while (( fgets(fp1)!=EOF)
    {
     for(i=0,i<2500,i++)
     {
       for(j=0,j<5,j++)
     }

     fscanf(fp1,"%s",&A[i][j])
    }

    fp2=fopen(file2,"r");
    if ( fp2 == NULL )
    {
        printf("Cannot open %s for reading \n", file2 );
        exit(1);
    }

    while (( fgets(fp1)!=EOF)
    {
     for(i=0,i<2500,i++)
     {
       for(j=0,j<5,j++)
     }

     fscanf(fp2,"%s",&B[i][j])
    }

    x[i][j]=strcmp(A[i][1],B[i][1]);
    if(x=0)
    {
    printf("%s /n %s " x[i][j])
    }
    fclose(fp1)
    fclose(fp2)

    return 0;
    }

Edited 4 Years Ago by celina1234: editing

ok i have sorted the above problem but now am facing another.
my code now reads :

#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fp1 ,*fp2;
char ca , cb;
int i,j,x,s;
char A[i][j],B[i][j];
char file1[1024],file2[1024];
printf(" Enter file1: ",file1);
gets(file1);
printf("Enter file2: ",file2);
gets(file2);
fp1=fopen(file1,"r");
if ( fp1 == NULL )
    {
        printf("Cannot open %s for reading \n", file1 );
        exit(1);
    }
     while ((fgets(file1,sizeof file1,stdin))!=EOF)
    {
     for(i=0;i<2500;i++)
     {
       for(j=0;j<5;j++)
     {

     fscanf(fp1,"%s",&A[i][j]);
    }
     }
    }
    fp2=fopen(file2,"r");
    if ( fp2 == NULL )
    {
        printf("Cannot open %s for reading \n", file2 );
        exit(1);
    }

    while (fgets(file2,sizeof file2,stdin)!=EOF)
    {
     for(i=0;i<2500;i++)
     {
       for(j=0;j<5;j++)
     {

     fscanf(fp2,"%s",&B[i][j]);
    }
     }
    }
     if(strcmp(A[i][j],B[i][j]))==0;   

`

    {
    printf("%s /n %s  ",strcmp(A[i][j],B[i][j]));
    }

    fclose(fp1);
    fclose(fp2);

 return 0;
    }

but it shows syntax error before "==" token. ( which is 49th line ) Thanks.

Edited 4 Years Ago by celina1234: typing error

Thanks i corrected it. The code is now compiled successfully but its not running? Any reason why is this as such ?

You're using i and j to make your arrays before they have been given a value! Line 8.

Unless you have a compiler that recognizes the most recent version of c++ standards that line 8 won't compile. I think recent version of gcc is ok. There are no versions of Microsoft compilers that will compile it.

Edited 4 Years Ago by Ancient Dragon

This article has been dead for over six months. Start a new discussion instead.