#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char s[128]; char p[128]; char sl[128]; char *nomefile; char stringheConcatenate[128]=""; FILE *pfin, *pfout;
int lung =1;
int Nstringhe =1;
pfin = fopen("stringhe.txt", "r");
if (pfin == NULL) {
printf("Non posso aprire il file %s\n", "stringhe.txt");
exit(-1);
}
fscanf(pfin,"%s", p); strcpy(sl, p);
strcpy(stringheConcatenate, p);
while(!feof(pfin)) {
fscanf(pfin,"%s", s);
if (!strcmp(p,s)) lung++; if (strlen(s)>strlen(sl))
strcpy(sl, s); if (Nstringhe <=5)
strcat(stringheConcatenate, s);
Nstringhe++;
}
fflush(pfin);
fclose(pfin); nomefile = (char *) calloc (strlen(sl)+4+1, sizeof(char));
if (nomefile == NULL) {
printf("E' finita la memoria");
exit(-1);
} sprintf(nomefile, "%s.txt", sl);
pfout = fopen(nomefile, "w");
if (pfout == NULL) {
printf("Non posso aprire il file %s\n", nomefile);
exit(-1);
}
fprintf(pfout, "%d", lung); printf("La stringa concatenata e' %s", stringheConcatenate);
fflush(pfout);
fclose(pfout);
free(nomefile);
fflush(stdin);
getchar();
return 0;
}