- Codice: Seleziona tutto
#include <stdio.h>
#include <stdlib.h>
#include <string.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]);
void 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, *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);
verify_and_put(head, &em_2, tmp);
}
}
fclose(fpTMP);
}
printf_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])
{
char *s;
fscanf(fp, "%s", tmp);
s=tmp;
while(s!=NULL)
{
if(strcmp(s,"@")==0)
{
*(found)=1;
*(em_1)++;
break;
}
s++;
}
}
void correct(char tmp[MAXWORD])
{
int cont=0;
char *s, *t;
s=tmp;
while(s!=NULL)
if(isalpha(*s))
cont++;
t=(char *)malloc(sizeof(char)*cont + 1);
s=tmp;
while(s!=NULL)
{
if(isalpha(*s))
{
if(isupper(*s))
tolower(*s);
*t=*s;
t++;
}
s++;
}
strcpy(tmp,t);
free(t);
}
void verify_and_put(adv_l *head, int *em_2, char tmp[MAXWORD])
{
int ver;
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)++;
}
}
adv_l *put(avd_l *head, char tmp[MAXWORD])
{
adv_l *t;
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;
while(s!=NULL)
{
fprintf(fp, "%s", s->email);
s=s->next;
}
}
questo programma legge il file files.txt
- Codice: Seleziona tutto
nome1.txt
nome2.txt
apre i 2 file elencati dentro
nome1
- Codice: Seleziona tutto
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>
nome2
- Codice: Seleziona tutto
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'
e deve darmi un file di output con tutti gli indirizzi email, senza duplicati, apici, caratteri "< > " e tutti in minuscolo.
Mi da errore alla funzione puts....qualcuno ha un'idea?
