Sortail
How would one feel when u type a nice post , and then accidentally hitsome combination of keys in Frontpage and suddenly as if struck by a
lightning , everything that u have typed till then vanishes into thin
air like smoke...Well, believe me, it doesn't feel goood.
That was exactly what happened when I was mid-way through typing the
first and now dead version of this post about Sortail, a program to
remove repetitions in the output file produced by "Email Ripper". By
the way , what is "Email Ripper" ? To know that u must see the post
below....
This code is not entirely pretty... but still to use for a while its is ok...
When on earth shall I learn to write K&R - style C-programs ..... ?
Only God and my Ma Knows :-(
Anyways, have a look guys, after all it works...
AamzillaA
//Sortail
//Copyright 2007, AamzillaA
//13th November,2007
//Sortail is a program that reads a file 'emails.txt'
//and stores each email in an array and eleminates all repetitions and
//sorts the list of email addresses alphabetically and
//writes them to an output file.
#include
#include
#include
# define EMAIL_LENGTH 60
# define NUMBER_OF_EMAILS 1000
void main()
{
char ch;
char emails[NUMBER_OF_EMAILS][EMAIL_LENGTH];
int i=0,j=0,compare=1,email_start_flag=0;
FILE *ip_fptr,*op_fptr;
ip_fptr=fopen("emails.txt","rb");
clrscr();
printf("\nSortail \n\n");
printf("\n Copyright 2007, AamzillaA \n");
printf("\n Sortail takes emails.txt produced by 'Email Ripper'\n");
printf("\n and replaces all repeating emails with the string
'***Repetition***'\n");
printf("\n and outputs them in a file called 'sortail.txt'\n");
printf("\n ( Future versions of Sortail may produce a sorted list ) \n ");
printf("\n *** Make sure that u have a file named emails.txt in the
current directory \n");
getch();
ch=getc(ip_fptr);
while(ch != EOF)
{
if ((ch==',') || ch==' ')
{
email_start_flag=1;
}
if(email_start_flag==1 && ch==',')
{
email_start_flag=0;
emails[i][j]='\0';
i++; // incrementing index of array email to hold next email id
j=0;
}
if(email_start_flag==1 && ch !=',')
{
emails[i][j] = ch;
j++;
}
ch=getc(ip_fptr);
}// go and fetch next character
for(i=0;i
{
for(j=1;j
{
compare= strcmp(emails[i],emails[j]);
if((compare==0) && (i != j))
{
strcpy(emails[j],"* Repetition *\0");
}
}
}
/*
// code to print array emails[][]
for(i=0;i
{
printf("\n %d ) %s",i,emails[i]);
getch();
}
getch();
// */
fclose(ip_fptr);
op_fptr=fopen("sorted.txt","wb");
for(i=0;i
{
j=0;
while(emails[i][j] != '\0')
{
//printf("%c", emails[i][j]);
putc(emails[i][j],op_fptr); // writing to file sorted.txt
j++;
}
putc(',',op_fptr);
//AamzillaA
printf("\n");
//getch();
}
fclose(op_fptr);
printf("\n All repetitions in Emails.txt eleminated \n");
printf(" and Sorted.txt is created\n");
printf("\n Thanks for using Sortail \n AamzillaA at gmail dot com \n");
getch();
}// end of main

No comments:
Post a Comment