#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define MAXLN 10
#define MAXWORD 30
typedef struct adv_l
{
char email[MAXWORD];
struct adv_l *next;
}adv_l;
void open_file(FILE **fp, char fileIN[MAXLN]);
void open_w_file(FILE **fp, char fileIn[MAXLN]);
void search(FILE *fp, int *found, int *em_1, char tmp[MAXWORD]);
void correct(char tmp[MAXWORD]);
adv_l *verify_and_put(adv_l *head, int *em_2, char tmp[MAXWORD]);
adv_l *put(adv_l *head, char tmp[MAXWORD]);
void destroy_list(adv_l *head);
void print_file(FILE *fp, adv_l *head);
int main()
{
FILE *fp=NULL, *fpTMP, *fpOUT;
adv_l *head=NULL;
char fIN[MAXLN], fOUT[MAXLN], fBIS[MAXLN], tmp[MAXWORD];
int found=0, em_1=0, em_2=0;
printf("Inserire nome file input:\n");
scanf("%s", fIN);
open_file(&fp, fIN);
printf("Inserire nome file output:\n");
scanf("%s", fOUT);
open_w_file(&fpOUT, fOUT);
while(!feof(fp))
{
fscanf(fp, "%s", fBIS);
open_file(&fpTMP, fBIS);
while(!feof(fpTMP))
{
search(fpTMP, &found, &em_1, tmp);
if(found==1)
{
correct(tmp);
head=verify_and_put(head, &em_2, tmp);
}
}
fclose(fpTMP);
}
print_file(fpOUT, head);
fclose(fp);
fclose(fpOUT);
printf("Indirizzi e-mail nel file input: %d\n", em_1);
printf("Indirizzi e-mail nel file output: %d\n", em_2);
return EXIT_SUCCESS;
}
void open_file(FILE **fp, char fileIN[MAXLN])
{
if(((*fp)=fopen(fileIN,"r"))==NULL)
{
printf("Errore apertura file\n");
exit(1);
}
}
void open_w_file(FILE **fp, char fileIN[MAXLN])
{
if(((*fp)=fopen(fileIN,"w"))==NULL)
{
printf("Errore apertura file\n");
exit(1);
}
}
void search(FILE *fp, int *found, int *em_1, char tmp[MAXWORD])
{
int i=0;
(*found)=0;
fscanf(fp, "%s", tmp);
while(tmp[i]!='\0')
{
if(tmp[i] == '@')
{
(*found)=1;
(*em_1)++;
printf("* %s\n", tmp);
break;
}
i++;
}
}
void correct(char tmp[MAXWORD])
{
int cont=0, i=0, j=0;
char *t;
while(tmp[i]!='\0')
{
if(isalpha(tmp[i]) || tmp[i] == '@' || tmp[i]=='.')
cont++;
i++;
}
t=(char *)malloc(sizeof(char)*(cont + 1));
i=0;
while(tmp[i]!='\0')
{
if(isalpha(tmp[i]))
{
if(isupper(tmp[i]))
tmp[i]=tolower(tmp[i]);
t[j]=tmp[i];
j++;
}
else if(tmp[i]=='@' || tmp[i]=='.')
{
t[j]=tmp[i];
j++;
}
i++;
}
tmp[cont+1]='\0';
strcpy(tmp,t);
free(t);
printf("%s %s\n", tmp, t);
}
adv_l *verify_and_put(adv_l *head, int *em_2, char tmp[MAXWORD])
{
int ver=0;
adv_l *s;
s=head;
if(s == NULL)
{
head=put(head,tmp);
(*em_2)++;
}
else
{
while(s!=NULL)
{
if(strcmp(s->email,tmp)==0)
{
ver=0;
break;
}
else
ver=1;
s=s->next;
}
}
if(ver==1)
{
head=put(head,tmp);
(*em_2)++;
}
return head;
}
adv_l *put(adv_l *head, char tmp[MAXWORD])
{
adv_l *t=NULL;
t=(adv_l *)malloc(sizeof(adv_l));
strcpy(t->email,tmp);
t->next=head;
head=t;
return head;
}
void destroy_list(adv_l *head)
{
adv_l *t;
while(head!=NULL)
{
t=head;
head=head->next;
free(t);
}
head=NULL;
}
void print_file(FILE *fp, adv_l *head)
{
adv_l *s;
s=head;
while(s!=NULL)
{
fprintf(fp, "%s\n", s->email);
s=s->next;
}
}
questo programma legge il primo file con questi nomi
nome1.txt
nome2.txt
che sono nomi di altri files che va ad aprire
I docenti del corso di Tecniche e Linguaggi di Programmazione sono:
I Corso: prof. Elio Piccolo, tel. 7002, email: Elio Piccolo <elio.piccolo@polito.it>
II Corso: prof. Pietro Laface, tel. 7004, email: Pietro Laface <pietro.laface@polito.it>
III Corso: prof. Stefano Quer, tel. 7006, email: Stefano Quer <stefano.quer@polito.it>
Write to goofy@disney.com to get help on this assignment:
Me@myhome.it is my address, while OGRE@darkforest.net is
not mine, but Sherk's, so you shouldn't write to
ogre@darkforest.net
Both <liza@polito.it> and "pamela@polito.it" are fancy
Addresses (and you can write them as Liza@Polito.IT
or 'PaMeLa@pOlItO.IT'
ne deve estirpare gli indirizzi email, cambiarli tutti in minuscolo, togliere segni particolari come <> e "", e memorizzarli in un file di output, facendo attenzione a non inserire nell'output indirizzi email già presenti...c'è qualcuno che riesce a darmi una mano?