954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

EASY question? checking for line feed (return) in a html file with C++

is it just me or am i stupid? (save the comments har har)

im using C++ to pull in a character from a file ... (going character by character)

how do i check for a line feed, or return?

<img src="http://image.jpg"  <-- return
alt="image" height="100" width="100 />


ive checked for currentChar == '\n', =='CRLF', every possibility...

i cant seem to find anything on the web ...

any help would be great...thanks

jaeSun
Light Poster
31 posts since Oct 2004
Reputation Points: 12
Solved Threads: 0
 

You're not using an input function that skips whitespace (which includes newlines), are you?

Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

no...right now, if there are newlines or whatever, it prints them out .... but i dont want that

but i am skipping any extraneous whitespace

<img       src= ..../>
turns into
<img src=..../>


this is the code:

(its not the most effecient, its just a basic program for a web design class to print out the tree structure)

#include<iostream>
using namespace std;

int main()
{

  char currentChar, peekChar, prevChar;
  int tabIndex, tabSize, innerLength, subIndex, numSpaces;
  int i;

  tabIndex = 0;
  tabSize = 4;
  innerLength = 0;


  while (!cin.eof())
    {

      currentChar =  cin.get();

      if (currentChar == '<')
        {
          peekChar = cin.peek();

          if (peekChar == '!')
            {
              tabIndex--;
            }

          if (peekChar == '/')
            {
              subIndex = 1;
            }
          else
            {
              tabIndex++;
            }

          if (peekChar == '\n')
            {
              cout<<"::::::::FOUND AN END OF LINE CHARACTER::::::::::::::::";
            }


          for (i=0; i<(tabIndex*tabSize); i++)
            {
              cout<<" ";
            }

          while(currentChar != '>')
            {
              cout<<currentChar;
              prevChar = currentChar;
              currentChar = cin.get();
              if (currentChar == ' ')
                {
                  cout<<currentChar;
                  while (currentChar == ' ')
                    {
                      currentChar = cin.get();
                    }
                }
            }

          if (prevChar == '/')
            {
              subIndex = 1;
            }

          if (subIndex == 1)
            {
              tabIndex--;
              subIndex = 2;
            }

          cout<<currentChar<<endl;
        }
    }

  return 0;
}


i want it to print it without newlines:

<img 
src="http....." />

is printed as

<img src="http...." />


so yea, im trying to get rid of any extraneous whitespace, and check for newlines so i can get rid of it and print on one line

jaeSun
Light Poster
31 posts since Oct 2004
Reputation Points: 12
Solved Threads: 0
 

also, here is part of the output:

<div class="validate">
                        <a href="http://validator.w3.org/check?uri=referer">
                            <img src="http://www.w3.org/Icons/valid-xhtml10" 
 alt="Valid XHTML 1.0 Strict!" height="31" width="88" />
                        </a>
                        <a href="http://jigsaw.w3.org/css-validator/check/referer">
                            <img src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!" height="31" width="88" />
                        </a>
                        
                        
                        <a href="http://www.whiteazn.com/satworld/contact/feedback.php">
                        </a>
                    </div>
                    <div class="rowClear">
                    </div>
                </div>


as you can see, i just want it to print on one line ...

like this:

<div class="validate">
                        <a href="http://validator.w3.org/check?uri=referer">
                            <img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0 Strict!" height="31" width="88" />
                        </a>
                        <a href="http://jigsaw.w3.org/css-validator/check/referer">
                            <img src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!" height="31" width="88" />
                        </a>
                        
                        
                        <a href="http://www.whiteazn.com/satworld/contact/feedback.php">
                        </a>
                    </div>
                    <div class="rowClear">
                    </div>
                </div>
jaeSun
Light Poster
31 posts since Oct 2004
Reputation Points: 12
Solved Threads: 0
 

Don't you want the newline check inside the inner while loop? You've checked for a '<' followed immediately by a newline if I'm reading that correctly.

Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

hmm, i never thought of that ... ill go try that out ... stupid me ..

jaeSun
Light Poster
31 posts since Oct 2004
Reputation Points: 12
Solved Threads: 0
 

yup, that was it ..... geeeeeeeeeeeeeeeeeez stupid me

jaeSun
Light Poster
31 posts since Oct 2004
Reputation Points: 12
Solved Threads: 0
 

Enlighten me: if you knew in advance it was so easy why even bother asking and not just think about it yourself and get a solution?

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You