Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Go Back   Code Forums > Application and Web Development > Standard C, C++
User Name
Password

Reply
 
LinkBack Thread Tools Display Modes
Old 05-05-2008, 03:20 PM   #1 (permalink)
Terrorist
Recruit
 
Join Date: May 2008
Posts: 2
Terrorist is on a distinguished road
Angry HTML tags validator

Hello Everyone,

I have done this code in C to read a HTML string from the keyboard, parse the tags and store them into a stack, then print it out.

Now I am trying to take of the Closing Tags from the stacks (aka. /html) and store them into another array.However, I have a problem with that. Could you please help me in this, I have commented the code where it SHOULD copy the closing tags to another array.

Code:
#include <stdio.h> #define B_OPEN '<' #define B_CLOSE '>' #define BRACKET_MAX 10 #define B_CHAR_MAX 7 char bracket[BRACKET_MAX][B_CHAR_MAX]; int diagnosis; signed char bracket_nr, close_nr; /******************** Prototypes ***********************/ /********************************************************/ /********************************************************/ int push (void); int writetags (void); /******************** Main ***********************/ /********************************************************/ /********************************************************/ int main (void){ extern int diagnosis; extern signed char bracket_nr; char c; bracket_nr=-1; diagnosis=0; while((c=getchar())!=EOF && c!='\n'){ if(c==B_OPEN){ diagnosis=push(); }; switch (diagnosis){ case -3: printf("infinate bracket.\n"); break; case -5: printf("Too Large Bracket.\n"); break; case -7: printf("Too many bracket.\n"); break; }; if (diagnosis < 0) break; }; if(diagnosis==0){ printf("No brackets.\n"); }else if (diagnosis > 0){ printf("You have written %d brackets; they are:\n",diagnosis); writetags(); }else{ printf("Text contains errors.\n"); }; system ("PAUSE"); return diagnosis; }; /******************** Push Function**********************/ /********************************************************/ /********************************************************/ int push (void){ extern char bracket [BRACKET_MAX][B_CHAR_MAX]; extern int diagnosis; extern signed char bracket_nr; char c, bracket_char; c=getchar(); bracket_nr++; if(bracket_nr>=BRACKET_MAX) return (diagnosis = -7); //to many tags diagnosis=bracket_nr+1; for(bracket_char=0;c!=EOF && c!='\n' && c!=B_CLOSE && bracket_char<B_CHAR_MAX;bracket_char++, c=getchar()){ //record tag name into the stack bracket bracket[bracket_nr][bracket_char]=c; }; bracket[bracket_nr][bracket_char]='\0'; if(c==B_CLOSE){ return diagnosis; }else if (bracket_char>=B_CHAR_MAX){ return(diagnosis=-5); }else if (c==EOF || c=='\n') return (diagnosis=-3); return diagnosis; }; /******************** writetags function ***************/ /********************************************************/ /********************************************************/ int writetags (void) { extern char bracket[BRACKET_MAX][B_CHAR_MAX]; char close[BRACKET_MAX][B_CHAR_MAX]; extern int diagnosis; extern signed char bracket_nr, close_nr; char bracket_char, close_char; for(;bracket_nr>=0; bracket_nr--){ for(bracket_char=0; bracket[bracket_nr][bracket_char]!='\0'; bracket_char++){ putchar(bracket[bracket_nr][bracket_char]); } putchar('\n'); } /*****************************************START: TO COPY and PRINT CLOSING TAGS*************************************/ close_nr=0; for(;bracket_nr>=0; bracket_nr--, close_nr++){ if (bracket_char=='/'){ for(close_char=0, bracket_char=0; bracket[bracket_nr][bracket_char]!='\n'; bracket_char++, close_char++){ close[close_nr][close_char]=bracket[bracket_nr][bracket_char];}}} close[close_nr][close_char]='\0'; printf("Off tags are:\n"); for(;close_nr>=0; close_nr--){ for(close_char=0; close[close_nr][close_char]!='\0'; close_char++){ putchar(close[close_nr][close_char]); } putchar('\n'); } /*****************************************END: TO COPY and PRINT CLOSING TAGS*************************************/ };
__________________
Terrorist is offline   Reply With Quote
Old 05-06-2008, 03:54 PM   #2 (permalink)
Terrorist
Recruit
 
Join Date: May 2008
Posts: 2
Terrorist is on a distinguished road
I have solved the problem, thanks.
__________________
Terrorist is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Optional Closing Tags in HTML CALM HTML, XML, Javascript, AJAX 1 10-03-2007 08:26 AM
Using regular expressions to clean HTML in user input NirTivAal PHP 3 05-23-2006 10:19 PM
Validating Your Pages With the W3C Markup Validator verto HTML / CSS 0 08-11-2003 06:17 PM
An Introduction to XHTML/CSS Rie HTML / CSS 0 03-07-2003 06:50 PM
Making a basic page in HTML MiLady Mirlyn HTML / CSS 0 02-16-2003 01:36 PM


All times are GMT -8. The time now is 09:35 PM.


Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle