Write a C program to count the number of email on text
Answer / Ashish Kumar Vimal
Here's a simple C program that counts the number of emails in a given text file. This example assumes emails are enclosed between '<' and '>' brackets, with '@' separating the local and domain names.nn```cn#include <stdio.h>n#include <stdlib.h>n#include <string.h>nnvoid count_emails(FILE *fp);nint main() {n FILE *fp;n char filename[100];n printf("Enter the file name: ");n scanf("%s", filename);n fp = fopen(filename, "r");n if (fp == NULL) {n perror("Error opening file.");n return 1;n }n count_emails(fp);nfclose(fp);n return 0;n}nnvoid count_emails(FILE *fp) {n int total = 0,n local = 0,n domain = 0;n char ch;n while ((ch = fgetc(fp)) != EOF) {n if (ch == '<') {n local = 1;n }n if (ch == '>') {n if (local == 1 && ch == '@') {n local = 2;n domain = 1;n }n if (domain == 1 && isalpha(ch)) {n domain++;n }n if (local != 2) {n local = 0;n }n }n if (domain == 3) {n total++;n domain = 0;n }n }n printf("Number of emails: %d", total);n}n```
| Is This Answer Correct ? | 0 Yes | 0 No |
Explain what are the __date__ and __time__ preprocessor commands?
what is real time system?what is the differance between hard and soft real time systems
tell me the full form of c?
How we can insert comments in a c program?
write a C program : To find out the number of identical words in two files . the file name should be taken as command line argument .
What is the difference between int and float?
There seem to be a few missing operators ..
main() { int a[3][4] ={1,2,3,4,5,6,7,8,9,10,11,12} ; int i, j , k=99 ; for(i=0;i<3;i++) for(j=0;j<4;j++) if(a[i][j] < k) k = a[i][j]; printf("%d", k); }
4 Answers Vector, Wipro, Zoho,
what do you mean by inline function in C?
Dont ansi function prototypes render lint obsolete?
Can i use “int” data type to store the value 32768? Why?
How to write a program to receive an integer & find its octal equivalent by using for loop?