C Codes
Beginners
C on Unix
Code Snippets
Data Structures
File Operations
Games Graphics
Gnu-Linux
Hardware
Mathematics
Miscellaneous
Small Programs
Sorting
C > Small Programs sample source codes
Split mail header-body
Split mail header-body #include <stdio.h> #include <string.h> #define IN 1 #define OUT 0 #define MAX 1024 void header(FILE *fp); void body(FILE *fp); char line[MAX]; int state = 0; int main(int argc, char *argv[]) { (argc == 2) && (strcmp(argv[1], "-b") == 0) ? body(stdin) : header(stdin); return 0; } void header(FILE *fp) { while((fgets(line, MAX, fp)) != NULL) { if(strstr(line, "From ")) (state = IN); (state == IN && strlen(line) > 1) ? printf("%s", line) : (state = OUT); } } void body(FILE *fp) { while((fgets(line, MAX, fp)) != NULL) { if(strstr(line, "From ")) (state = OUT); if(state == OUT && strlen(line) < 2) (state = IN); if(state == IN) printf("%s", line); } }
Privacy Policy
|
Link to Us
|
Links