the file which i have to read is:
From sms@localhost.localdomain Wed May 16 10:46:03 2007
Return-Path: <sms@localhost.localdomain>
Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
by localhost.localdomain (8.13.5/8.13.5) with ESMTP id l4GEk300002418
for <sms@localhost.localdomain>; Wed, 16 May 2007 10:46:03 -0400
Received: (from sms@localhost)
by localhost.localdomain (8.13.5/8.13.5/Submit) id l4GEk3H3002417
for sms; Wed, 16 May 2007 10:46:03 -0400
Date: Wed, 16 May 2007 10:46:03 -0400
From: sms@localhost.localdomain
Message-Id: <200705161446.l4GEk3H3002417@localhost.localdomain >
To: sms@localhost.localdomain
Subject: mail 1
030044444
1st mail to be sent
by sms
From sms@localhost.localdomain Wed May 16 10:46:43 2007
Return-Path: <sms@localhost.localdomain>
Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
by localhost.localdomain (8.13.5/8.13.5) with ESMTP id l4GEkhdo002426
for <sms@localhost.localdomain>; Wed, 16 May 2007 10:46:43 -0400
Received: (from sms@localhost)
by localhost.localdomain (8.13.5/8.13.5/Submit) id l4GEkhRa002425
for sms; Wed, 16 May 2007 10:46:43 -0400
Date: Wed, 16 May 2007 10:46:43 -0400
From: sms@localhost.localdomain
Message-Id: <200705161446.l4GEkhRa002425@localhost.localdomain >
To: sms@localhost.localdomain
Subject: 2nd mail
09888766
2nd mail to be sent
for df
From sms@localhost.localdomain Wed May 16 10:47:55 2007
Return-Path: <sms@localhost.localdomain>
Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
by localhost.localdomain (8.13.5/8.13.5) with ESMTP id l4GEltPQ002436
for <sms@localhost.localdomain>; Wed, 16 May 2007 10:47:55 -0400
Received: (from sms@localhost)
by localhost.localdomain (8.13.5/8.13.5/Submit) id l4GEltF0002435
for sms; Wed, 16 May 2007 10:47:55 -0400
Date: Wed, 16 May 2007 10:47:55 -0400
From: sms@localhost.localdomain
Message-Id: <200705161447.l4GEltF0002435@localhost.localdomain >
To: sms@localhost.localdomain
Subject: 3rd mail
099888776
3rd mail for user
gsg
from this file i have to read lines below the "subject:" from there i have to read number and then the written e-mail right now i am able to just red the 1st number and mail below it i don't know what to do to read the 2nd and 3rd or any no. of mails from this file.
the code i have written is below will be really greatful for assisstance - #include <stdio.h>
-
main()
-
{
-
FILE * kp;
-
char classmain[100];
-
int i=0, j=0,x=0;
-
//flag f=0;
-
kp=fopen("sms","r");
-
//fread(classmain,0,10000,kp);
-
-
if(kp==NULL)
-
{
-
printf("unable to open the file");
-
exit(1);
-
}
-
while(!feof(kp))
-
{
-
while(fgets(classmain,100,kp) != NULL)
-
{
-
//fputs(classmain, stdout);
-
//printf("%s", classmain);
-
if (strstr(classmain,"Subject"))
-
//printf("%s", classmain);
-
break;
-
}
-
while(fgets(classmain,100,kp)!= NULL)
-
{
-
if(strcmp(classmain,"")!=0)
-
break;
-
}
-
fgets(classmain,100,kp);
-
printf("%s",classmain);
-
-
while(fgets(classmain,100,kp)!=NULL)
-
{
-
if(strcmp(classmain,"")==0)
-
break;
-
printf("%s",classmain);
-
}
-
while(fgets(classmain,100,kp) != NULL)
-
{
-
//fputs(classmain, stdout);
-
//printf("%s", classmain);
-
if (strstr(classmain,"Subject"))
-
printf("%s", classmain);
-
break;
-
}
-
-
}//end of 1st while
-
-
fclose(kp);
-
}
5 2198
Please indent your code. I'm not going to do it for you and I won't look at it till it is.
It is just too hard to read.
Adrian
i have provided it in indented form but when it displays on web there aren't any indentation it is opening in indented form in edit mode kindly check that out - #include <stdio.h>
-
main()
-
{
-
FILE * kp;
-
char classmain[100];
-
int i=0, j=0,x=0;
-
-
kp=fopen("sms","r");
-
if(kp==NULL)
-
{
-
printf("unable to open the file");
-
exit(1);
-
}
-
-
while(!feof(kp))
-
{
-
-
while(fgets(classmain,100,kp) != NULL)
-
{
-
if (strstr(classmain,"Subject"))
-
break;
-
}
-
-
while(fgets(classmain,100,kp)!= NULL)
-
{
-
if(strcmp(classmain,"")!=0)
-
break;
-
}
-
fgets(classmain,100,kp);
-
printf("%s",classmain);
-
-
while(fgets(classmain,100,kp)!=NULL)
-
{
-
if(strcmp(classmain,"")==0)
-
break;
-
printf("%s",classmain);
-
}
-
while(fgets(classmain,100,kp) != NULL)
-
{
-
if (strstr(classmain,"Subject"))
-
printf("%s", classmain);
-
break;
-
}
-
-
}//end of 1st while
-
-
fclose(kp);
-
}//end of main
You have to use [code][/code] tags, with the first tag stating what language it is. For C, use [code=c], for C++ use [code=cpp].
Even in edit I had problems reading it. so I've run it through a programme called indent using -kr switch. This is what I got: - #include <stdio.h>
-
main()
-
{
-
FILE *kp;
-
char classmain[100];
-
int i = 0, j = 0, x = 0;
-
-
kp = fopen("sms", "r");
-
if (kp == NULL) {
-
printf("unable to open the file");
-
exit(1);
-
}
-
-
while (!feof(kp)) {
-
-
while (fgets(classmain, 100, kp) != NULL) {
-
if (strstr(classmain, "Subject"))
-
break;
-
}
-
-
while (fgets(classmain, 100, kp) != NULL) {
-
if (strcmp(classmain, "") != 0)
-
break;
-
}
-
fgets(classmain, 100, kp);
-
printf("%s", classmain);
-
-
while (fgets(classmain, 100, kp) != NULL) {
-
if (strcmp(classmain, "") == 0)
-
break;
-
printf("%s", classmain);
-
}
-
while (fgets(classmain, 100, kp) != NULL) {
-
if (strstr(classmain, "Subject"))
-
printf("%s", classmain);
-
break;
-
}
-
-
} //end of 1st while
-
-
fclose(kp);
-
} //end of main
I find this much more readable. (except perhaps the colours. We are looking into changing them ;))
Please reply to this message and put comments for each loop telling me what you are trying to accomplish.
Adrian
i have made changes to the logic
the new code is -
#include <stdio.h>
-
main()
-
{
-
FILE * kp;
-
char classmain[100];
-
int i=0, j=0, x=0;
-
kp=fopen("sms","r");
-
//if no file read do the following
-
if(kp==NULL)
-
{
-
printf("unable to open the file");
-
exit(1);
-
}
-
//else read the file
-
while(!feof(kp))
-
{
-
//read every string until find Subject in file and then break and move to next while
-
while(fgets(classmain,100,kp) != NULL)
-
{
-
if (strstr(classmain,"Subject"))
-
break;
-
}
-
-
while(fgets(classmain,100,kp)!= NULL)
-
{
-
//check for the blank lines writen after subject ignore spaces and read number and next two lines
-
if(strcmp(classmain," ")==1)
-
break;
-
}
-
if(feof(kp))
-
break;
-
printf("%s",classmain);
-
printf("%s",(fgets(classmain,100,kp)));
-
printf("%s",(fgets(classmain,100,kp)));
-
}//end of 1st while
-
fclose(kp);
-
}
-
this code is working and giving me desired output but still have logical problems
if(strcmp(classmain," ")==1)
in this condition i am comparing space with the string available in classmain while its not space its value in hex is 0a i checked the contents of my file using command
hexdump -C /sms
with what i should compare the string obtained?
do consider my file of mails with it and run this code and help me improving this thnx
i have made changes to the logic
the new code is -
#include <stdio.h>
-
main()
-
{
-
FILE * kp;
-
char classmain[100];
-
int i=0, j=0, x=0;
-
kp=fopen("sms","r");
-
//if no file read do the following
-
if(kp==NULL)
-
{
-
printf("unable to open the file");
-
exit(1);
-
}
-
//else read the file
-
while(!feof(kp))
-
{
-
//read every string until find Subject in file and then break and move to next while
-
while(fgets(classmain,100,kp) != NULL)
-
{
-
if (strstr(classmain,"Subject"))
-
break;
-
}
-
-
while(fgets(classmain,100,kp)!= NULL)
-
{
-
//check for the blank lines writen after subject ignore spaces and read number and next two lines
-
if(strcmp(classmain," ")==1)
-
break;
-
}
-
if(feof(kp))
-
break;
-
printf("%s",classmain);
-
printf("%s",(fgets(classmain,100,kp)));
-
printf("%s",(fgets(classmain,100,kp)));
-
}//end of 1st while
-
fclose(kp);
-
}
-
this code is working and giving me desired output but still have logical problems
if(strcmp(classmain," ")==1)
in this condition i am comparing space with the string available in classmain while its not space its value in hex is 0a i checked the contents of my file using command
hexdump -C /sms
with what i should compare the string obtained?
do consider my file of mails with it and run this code and help me improving this thnx
Look up strcmp() here. Or for comparing a single char, classmain[0] == ' ' would work too.
Adrian
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Chuck Anderson |
last post by:
Can anyone point me in the right direction? I want to use Php to
automate confirmation of someone joining an email list by them replying
to an email (so they don't have to have a browser?).
I...
|
by: Ilan |
last post by:
Hi all
I need to add data from two Excel sheets (both on the same workbook)
to an existing table in my SQL DB.
The problem is that each sheet holds different fields for the same
record, though...
|
by: hezhenjie |
last post by:
Hi, all:
I just need to parse a unicode file, and assume to get data one line
by one line.
I use _wfopen(), fgetws(), wcslen(), wcsstr(), making it work
normally on Windows platform.
However,...
|
by: VM |
last post by:
Is it possible to open an ascii file, read the first 499 lines, overwrite
line 500 with the new string, and close the file? All the lines before and
after line 500 will be untouched.
Thanks.
|
by: rudranee |
last post by:
hi there,
can anyone tell me how to lines from a file which are odd numbered i.e.
1st,3rd,5th...lines.
i tried incrementing file pointer by 2 (fp=fp+2)
but it does'nt work
Can someone give me...
|
by: Kinbote |
last post by:
Hi,
I'm trying to make a function that opens a file, reads it in line by
line, puts each line into an malloc'd array, and returns the array. I
suspect I'm going about it in an atypical fashion, as...
|
by: flebber |
last post by:
I was working at creating a simple program that would read the content
of a playlist file( in this case *.k3b") and write it out . the
compressed "*.k3b" file has two file and the one I was trying...
|
by: mazwolfe |
last post by:
Someone recently asked about reading lines. I had this code written
some time ago (part of a BASIC-style interpreter based on H. Shildts
in Art of C) to read a file with the lines ended in any...
|
by: tlpell |
last post by:
Hey, read some tips/pointers on PHP.net but can't seem to solve this
problem. I have a php page that reads the contents of a file and then
displays the last XX lines of the file. Problem is...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
| |