Hello ,
i'm working on a problem that i cant get to work. It's supposed to read character by character and store it.im focusing on the email part here..and this is my programme...it really bugs me i cant work it!!
id greatly appreciate any help , before i destroy my monitor :-)
Heidi
#include <stdio.h>
FILE *fin;
check_email(char *email)
{
int i, is_email=0;
for (i=0; i<40; i++)
if (email[i] == '@')
is_email++;
if (is_email == 1)
printf("%s is an email address\n", email);
}
processfile()
{
char ch, aword[40];
int i=0;
while ((ch = getc(fin)) != EOF) {
if (ch == ' ' || ch == '\t' || ch == '\n') {
aword[i] = '\0';
check_email(aword);
i = 0; }
else aword[i++] = ch; }
scanf("%c", &ch);
}
main()
{
char fname[41];
printf("Enter name of file to read: \n");
gets(fname);
fin = fopen(fname, "r");
if (fin == NULL)
printf("File cannot be opened.\n");
else { printf("\nFile exists.\n\n");
processfile(); }
fclose(fin);
}