Grazie per i suggerimenti e le spiegazioni...
Ho risolto così:
codice:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ( int argc, char * argv[] )
{
FILE *fda, *fdb, *fdout;
char *res1, *res2;
char bufa[200];
char bufb[200];
char *p1, *p2;
if ( argc != 4 ) {
printf("usare %s file1 file2 outfile\n",argv[0]);
return 1;
}
fda = fopen (argv[1], "r");
if ( fda == NULL) {
perror("Errore in apertura del file");
exit(1);
}
fdb = fopen (argv[2], "r");
if ( fdb == NULL) {
perror("Errore in apertura del file");
exit(1);
}
fdout = fopen (argv[3], "a");
while (1)
{
res1=fgets(bufa, 200, fda);
if( res1==NULL )
break;
if ((p1 = strchr (bufa, '\n')) != NULL)
*p1 = '\0';
res2=fgets(bufb, 200, fdb);
if( res2==NULL )
break;
if ((p2 = strchr (bufb, '\n')) != NULL)
*p2 = '\0';
fprintf( fdout ,"%s %s\n", res1, res2);
}
fclose ( fda);
fclose ( fdb);
fclose ( fdout);
return 0;
}
Ora lo testo su documenti da 5 MB. Con più di 2000 linee per file...
Vediamo cosa succede...