[Courses] How to get line-information from buffer..

sneha sneha at vit.ac.in
Mon Sep 30 11:37:08 EST 2002


**Hello :)

        something which I tried... :)
happy day
friendly
sneha :o)

consider a file named  "info" carries the following information:
-------------------------------------------------------------------------------

GET / HTTP/1.0
 Connection: Keep-Alive
 User-Agent: Mozilla/4.75 [en] (X11; U; Linux
 2.2.17-21mdk i686)
 Host: localhost:8000
 Accept: image/gif, image/x-xbitmap, image/jpeg,
 image/pjpeg, image/png, */*
 Accept-Encoding: gzip
 Accept-Language: en
 Accept-Charset: iso-8859-1,*,utf-8

C code :
----------
#include<stdio.h>
main()
{
FILE *f1;
char ch,*str;
int count=0;
f1=fopen("info","r");
str=(char *) calloc(sizeof(char *),80);
while((ch=fgetc(f1))!=EOF)
{
        if(ch=='\n')
        {
                count++;
        }
        if(count>2)
        {
                fgets(str,80,f1);
                break;
        }
}
printf("%s",str);
}    

==Output
    Host: localhost:8000 

Shell Script
---------------
$ head -n 4 info | tail -n 1  

== Ouput
      Host: localhost:8000    

$ head -n 4 info | tail -n 1 | cut -d ":" -f3 

== Ouput
        8000 

    
******************************************************************************


----- Original Message ----- 
From: Abel Pires da Silva <lybel_2000 at yahoo.com>
To: <courses at linuxchix.org>
Sent: Monday, September 30, 2002 10:37 AM
Subject: [Courses] How to get line-information from buffer..


> I got a buffer contents like below:
> 
> GET / HTTP/1.0
> Connection: Keep-Alive
> User-Agent: Mozilla/4.75 [en] (X11; U; Linux
> 2.2.17-21mdk i686)
> Host: localhost:8000
> Accept: image/gif, image/x-xbitmap, image/jpeg,
> image/pjpeg, image/png, */*
> Accept-Encoding: gzip
> Accept-Language: en
> Accept-Charset: iso-8859-1,*,utf-8
> 
> And I only interested to the fourth line of the
> message (host information), so I can make a string
> comparation with the list of addresses that I store in
> file.
> 
> How can I read/retrieve only the fourth line of the
> above format?
> 
> Or, is there any better way to do the comparation?
> Regards,
> Abel
> 
> __________________________________________________
> Do you Yahoo!?
> New DSL Internet Access from SBC & Yahoo!
> http://sbc.yahoo.com
> _______________________________________________
> Courses mailing list
> Courses at linuxchix.org
> http://mailman.linuxchix.org/mailman/listinfo/courses
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://linuxchix.org/pipermail/courses/attachments/20020930/4d28929b/attachment.xhtml


More information about the Courses mailing list