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

Recommended Answers

All 7 Replies

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

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

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>
                        <br />
                        <br />
                        <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>
                        <br />
                        <br />
                        <a href="http://www.whiteazn.com/satworld/contact/feedback.php">
                        </a>
                    </div>
                    <div class="rowClear">
                    </div>
                </div>

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.

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

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

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.