Thread: html read

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    151

    Post html read

    How do I make C compiler to read the source code of an external html file from the C compiler?

    Please reply.

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Uh . . . that's way out of your league. Writing a C compiler, that is.

    Explain what you're trying to do in more detail.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    151

    Arrow

    I have to write a program that will read the source code of any html and do some processes on its tags like <html>,<head>... etc.

  4. #4
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    You wouldn't be able to do this too effectively without a file stream: do you know how to use those? If you do:

    1. Open a file stream to some HTML document
    2. Read it line by line using fgets
    3. Parse that line
    4. ????
    5. PROFIT!!

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    As determined here, you'll want to use a stack.

    You'll need fopen(), fgets() or getc(), and fclose(). You can probably use an array for a stack and an int to store the location in the array. Something like this (this doesn't have error checking like stack under/overflow):
    Code:
    int array[SIZE], pos = 0;
    
    void push(int x) {
        array[pos++] = x;
    }
    
    int pop(void) {
        return array[--pos];
    }
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  6. #6
    Registered User
    Join Date
    May 2006
    Posts
    151

    Arrow

    I was planning of using stacks as the logic to get the dolution, but the tags to a html file will only b there in its source file. Hence if i use fopen on a html file, will i be able to reach its cource code?

  7. #7
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    Get an XML parcer librairy. XML is so simmilar to HTML that it should work just fine.

    And yes, HTML is just source code. Your Browser is what interperts the HTML into a hypertext web page.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  8. #8
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Don't forget that some HTML tags don't need a corresponding closing tag.
    If you understand what you're doing, you're not learning anything.

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    That was mentioned in another thread about this program: http://board.theprogrammingsite.com/viewtopic.php?t=161

    I was planning of using stacks as the logic to get the dolution, but the tags to a html file will only b there in its source file. Hence if i use fopen on a html file, will i be able to reach its cource code?
    Yes . . . that's what fopen does. It opens a file stream that you can read from. The data in the stream comes from a file.

    You might want to read this tutorial, and maybe some others in the same section: http://www.cprogramming.com/tutorial/cfileio.html
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. confused with read()
    By _EAX in forum Linux Programming
    Replies: 2
    Last Post: 03-17-2008, 04:14 PM
  2. Replies: 8
    Last Post: 03-10-2008, 11:57 AM
  3. Read source from a HTML online
    By tboy in forum C Programming
    Replies: 2
    Last Post: 11-22-2004, 08:10 PM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Read Array pro!!Plz help!!
    By Supra in forum C Programming
    Replies: 2
    Last Post: 03-04-2002, 03:49 PM