need direction. (first time on stack overflow, go easy)

Viewed 59

The code here is incomplete I know

go through a text(.txt) file and scan if the file contains emails in it, if yes, write the email and save into a new(.txt)file

I want to go through the text file and check for any emails in the file, i tried using a function is_email for this. I'm stuck there.

I also don't know how to pick out the specific string, write it to the file, then move on. Maybe I'm overthinking here.

I also feel a bit intimidated from the size of bigger files

#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>

char* is_email(char* buffer[], int buf_len);

int main(int argc, char* argv[])
{   
/*checking to see  if the program has correct no. of arguments.*/
    if (argc != 2)
    {
        return 1;
        printf("usage: ./emailscanner *.txt\n");
    }
    
    /*checking to see if the usage is correct, and the text file is there or not?*/
    FILE *in_file = fopen(argv[1], "r"); 
    FILE *out_file = NULL; 
    uint8_t buffer[512];
    /*ADD AN ERROR STATEMENT BASED ON THE HEADER SIGNATURE OF TEXT FILE.*/
    
    if(input_file == NULL)
    {
        printf("couldn't open file\n");
        return 2;
    }
        
    /* here input file would need to be REVIEWED.*/
    while(fread(in_file, sizeof(char), 1, output_file))
    {   
      if (buffer[0] == 0xef && buffer[1] == 0xbb && buffer[2] == 0xbf)
    
      {
        is_email(buffer);
      }
    
    } 
}

char* is_email(char* buffer[], int buf_len)
{
    int length;
    for(int i=0;i<length;i++)
    {
        if(buffer[i] = "@")
        {
            return buffer;
        }
        else next_buffer[]; 
    }   
}
0 Answers
Related