Q:

(C language ) Can i use an fopen instruction inside another fopen instruction?

well im writing a program where i saved some employee names and proffessions on a file ,
and i did another file where ive put the proffesions and its salary ,
and i wanna make a program which write every employee info and add it it its proper salary  ,
so i went to use an fread instruction to open the employee file , then while reading employe info ,
i did another fread that read from the salary file , to at the end print the proper salary for that employee ,
and on and on , but its not working , it gives me nothing , only employee infos without their salary , thanks for helping
code:
include <stdio.h>
#include <stdlib.h>
typedef struct { int d,m,y; } dtype ;

typedef struct { char nom[10]; char prenom[10] ; char poste[20]; dtype date ; } LEM ;

typedef struct { char postes[20]; int salaire ; } LP ;

int main()
{

    FILE * F;
    F= fopen("C:/Users/ipoga/Desktop/BUNCH OF STUFF/TP ALGO/auto/employés.db","r" );
    LEM R ;

    FILE * E;
    E= fopen("C:/Users/ipoga/Desktop/BUNCH OF STUFF/TP ALGO/auto/poste.db","r" );
    LP O  ;

    fread(&R , sizeof(R),1,F);
    while(!feof(F))
    {

     

        printf("nom : %s \t",R.nom);
        printf("prenom : %s \t",R.prenom);
        printf("poste : %s \t",R.poste);
        printf("date de rec : %d/%d/%d \n",R.date.d , R.date.m ,R.date.y);

                                fread(&O , sizeof(O),1,E);
                                while(!feof(E))
                                {

                                if(O.postes == R.poste)
                                {
                                    printf( "salaire : %d ",O.salaire);
                                }

                                fread(&O , sizeof(O),1,E);
                                }

        fread(&R , sizeof(R),1,F);

    }
 

}
 

A:

O.postes is a char[]. For a C style string, comparison should not be done with == (which compares the addresses, not the content) but with strcmp() from <string.h> instead.

