Thread: can't get this one to display properly

  1. #1
    Unregistered
    Guest

    Cool can't get this one to display properly

    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);
    }

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Try this:

    FILE *fin;
    check_email(char *email)
    {
    int i, is_email=0;
    for (i=0; i<strlen(email); i++) //*****Change this

    include <string.h> to use strlen().

  3. #3
    Registered User pinko_liberal's Avatar
    Join Date
    Oct 2001
    Posts
    284
    or equivalently use strchr.

    char* strchr(const char* cs, int c);
    Returns pointer to first occurrence of c in cs, or NULL if not found.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. display character size...(quite urgent..)
    By karthi in forum C Programming
    Replies: 10
    Last Post: 07-11-2007, 09:42 PM
  2. new problem with class
    By jrb47 in forum C++ Programming
    Replies: 0
    Last Post: 12-01-2006, 08:39 AM
  3. Help needed Please
    By jereland in forum C Programming
    Replies: 9
    Last Post: 03-18-2004, 05:30 AM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM