html parse help

This is a discussion on html parse help within the C Programming forums, part of the General Programming Boards category; Is there another logic for this purpose: Read through an input file for tags ex: <html> </html> <head> </head> and ...

  1. #1
    Ron
    Ron is offline
    Registered User
    Join Date
    May 2006
    Posts
    151

    Post html parse help

    Is there another logic for this purpose: Read through an input file for tags ex: <html> </html> <head> </head>
    and check if the other half of the pair is also present. If <html> is there, its other half< /html> should also be present. If not report an error message stating which tag is missing. For this question, I'm thinking to apply the following logic.

    Read throught the file till I get a '<' then put that whole tag like<head> in a stack and when I find the other half pop it from the stack.


    Is there a better, less strain logical way to to perform this application.

    Please advise.

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,163
    Using a stack would be the best way I can think of to easily handle nested tags.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Is there a better, less strain logical way to to perform this application.
    Nope, you pretty much outlined the best way to accomplish this task.

  4. #4
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    EDIT: Ok, misread the question

    You cold use a recursive function for this, too.
    Last edited by jafet; 06-12-2006 at 02:56 AM.
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    You cold use a recursive function for this, too.
    Using a recursive function uses the function stack. Can't escape stacks . . . .

    http://board.theprogrammingsite.com/viewtopic.php?t=161
    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. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  2. Submitting HTML form and parse respons
    By IdunnO in forum Networking/Device Communication
    Replies: 4
    Last Post: 03-07-2006, 09:28 AM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  4. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21