User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 391,588 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,643 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 3391 | Replies: 7
Reply
Join Date: Oct 2004
Posts: 31
Reputation: jaeSun is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
jaeSun jaeSun is offline Offline
Light Poster

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

  #1  
Nov 30th, 2004
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2004
Posts: 3,449
Reputation: Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light 
Rep Power: 16
Solved Threads: 138
Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

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

  #2  
Nov 30th, 2004
You're not using an input function that skips whitespace (which includes newlines), are you?
Reply With Quote  
Join Date: Oct 2004
Posts: 31
Reputation: jaeSun is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
jaeSun jaeSun is offline Offline
Light Poster

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

  #3  
Nov 30th, 2004
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
Reply With Quote  
Join Date: Oct 2004
Posts: 31
Reputation: jaeSun is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
jaeSun jaeSun is offline Offline
Light Poster

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

  #4  
Nov 30th, 2004
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>
Reply With Quote  
Join Date: Apr 2004
Posts: 3,449
Reputation: Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light 
Rep Power: 16
Solved Threads: 138
Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

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

  #5  
Nov 30th, 2004
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.
Reply With Quote  
Join Date: Oct 2004
Posts: 31
Reputation: jaeSun is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
jaeSun jaeSun is offline Offline
Light Poster

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

  #6  
Nov 30th, 2004
hmm, i never thought of that ... ill go try that out ... stupid me ..
Reply With Quote  
Join Date: Oct 2004
Posts: 31
Reputation: jaeSun is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
jaeSun jaeSun is offline Offline
Light Poster

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

  #7  
Nov 30th, 2004
yup, that was it ..... geeeeeeeeeeeeeeeeeez stupid me
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,646
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 191
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

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

  #8  
Dec 1st, 2004
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?
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C++ Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 11:03 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC