the file which i have to read is:
From sms@localhost.l ocaldomain Wed May 16 10:46:03 2007
Return-Path: <sms@localhost. localdomain>
Received: from localhost.local domain (localhost.loca ldomain [127.0.0.1])
by localhost.local domain (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.local domain (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.l ocaldomain
Message-Id: <200705161446.l 4GEk3H3002417@l ocalhost.locald omain>
To: sms@localhost.l ocaldomain
Subject: mail 1
030044444
1st mail to be sent
by sms
From sms@localhost.l ocaldomain Wed May 16 10:46:43 2007
Return-Path: <sms@localhost. localdomain>
Received: from localhost.local domain (localhost.loca ldomain [127.0.0.1])
by localhost.local domain (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.local domain (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.l ocaldomain
Message-Id: <200705161446.l 4GEkhRa002425@l ocalhost.locald omain>
To: sms@localhost.l ocaldomain
Subject: 2nd mail
09888766
2nd mail to be sent
for df
From sms@localhost.l ocaldomain Wed May 16 10:47:55 2007
Return-Path: <sms@localhost. localdomain>
Received: from localhost.local domain (localhost.loca ldomain [127.0.0.1])
by localhost.local domain (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.local domain (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.l ocaldomain
Message-Id: <200705161447.l 4GEltF0002435@l ocalhost.locald omain>
To: sms@localhost.l ocaldomain
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 2225 AdrianH 1,251
Recognized Expert Top Contributor
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
AdrianH 1,251
Recognized Expert Top Contributor
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(class main," ")==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
AdrianH 1,251
Recognized Expert Top Contributor
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(class main," ")==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 will probably use a hyperlink with a unique ID, but I also want to
know how to go about reading from a mailbox with Php so I can use an
email reply method, too.
I'm having trouble finding any kind of tutorial. From the bit of
searching I've done,...
|
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 the records are sorted by row numbers.
(I had to split the fields to different sheets because Excel has a
limit of 256 fields in each sheet)
My sheets are quite large (~55,000 rows and 200 columns each) and I'll
have to repeat this action many...
|
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, when migrate it to Linux platform, issue occurs.
Linux only has fopen() function, and fgetws() could not correctly get
lines, in fact, it gets nothing.
|
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 the code please.
| |
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 I'm avoiding the
use of fscanf and fgets to read in lines. I don't want to have to
specify a temporary char* buffer to read in each line, and then have
to concern myself with the (remote) possibility of overflows or with
increasing the buffer...
|
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 to read
was maindata.xml . I cannot however seem to use the gzip module
correctly. Have tried the program 2 ways for no success, any ideas
would be appreciated.
Attempt 1
#!/usr/bin/python
|
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 format:
Microsoft-style CR/LF pair, Unix-style NL, or Mac-style CR. It also
allows for EOF that does not follow a blank line. I thought this would
make text-file sharing a bit easier.
Here it is:
/* Load a file, normalizing newlines to *nix...
|
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 this...whenever
the file gets larger that ~5MB, the page just displays nothing, as
though a timeout has occurred but I get no error. At 4.8MB (last
confirmed size)...the function still works. Any ideas what code below
is lacking??
<?
$handle=...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |