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

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2004
Posts: 31
Reputation: jaeSun is an unknown quantity at this point 
Solved Threads: 0
jaeSun jaeSun is offline Offline
Light Poster

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

 
0
  #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?

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

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

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

any help would be great...thanks
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,343
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 237
Team 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++

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

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

 
0
  #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

  1. <img src= ..../>
  2. turns into
  3. <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)

  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.  
  7. char currentChar, peekChar, prevChar;
  8. int tabIndex, tabSize, innerLength, subIndex, numSpaces;
  9. int i;
  10.  
  11. tabIndex = 0;
  12. tabSize = 4;
  13. innerLength = 0;
  14.  
  15.  
  16. while (!cin.eof())
  17. {
  18.  
  19. currentChar = cin.get();
  20.  
  21. if (currentChar == '<')
  22. {
  23. peekChar = cin.peek();
  24.  
  25. if (peekChar == '!')
  26. {
  27. tabIndex--;
  28. }
  29.  
  30. if (peekChar == '/')
  31. {
  32. subIndex = 1;
  33. }
  34. else
  35. {
  36. tabIndex++;
  37. }
  38.  
  39. if (peekChar == '\n')
  40. {
  41. cout<<"::::::::FOUND AN END OF LINE CHARACTER::::::::::::::::";
  42. }
  43.  
  44.  
  45. for (i=0; i<(tabIndex*tabSize); i++)
  46. {
  47. cout<<" ";
  48. }
  49.  
  50. while(currentChar != '>')
  51. {
  52. cout<<currentChar;
  53. prevChar = currentChar;
  54. currentChar = cin.get();
  55. if (currentChar == ' ')
  56. {
  57. cout<<currentChar;
  58. while (currentChar == ' ')
  59. {
  60. currentChar = cin.get();
  61. }
  62. }
  63. }
  64.  
  65. if (prevChar == '/')
  66. {
  67. subIndex = 1;
  68. }
  69.  
  70. if (subIndex == 1)
  71. {
  72. tabIndex--;
  73. subIndex = 2;
  74. }
  75.  
  76. cout<<currentChar<<endl;
  77. }
  78. }
  79.  
  80. return 0;
  81. }

i want it to print it without newlines:

  1. <img
  2. src="http....." />
  3.  
  4. is printed as
  5.  
  6. <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 Quick reply to this message  
Join Date: Oct 2004
Posts: 31
Reputation: jaeSun is an unknown quantity at this point 
Solved Threads: 0
jaeSun jaeSun is offline Offline
Light Poster

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

 
0
  #4
Nov 30th, 2004
also, here is part of the output:

  1. <div class="validate">
  2. <a href="http://validator.w3.org/check?uri=referer">
  3. <img src="http://www.w3.org/Icons/valid-xhtml10"
  4. alt="Valid XHTML 1.0 Strict!" height="31" width="88" />
  5. </a>
  6. <a href="http://jigsaw.w3.org/css-validator/check/referer">
  7. <img src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!" height="31" width="88" />
  8. </a>
  9. <br />
  10. <br />
  11. <a href="http://www.whiteazn.com/satworld/contact/feedback.php">
  12. </a>
  13. </div>
  14. <div class="rowClear">
  15. </div>
  16. </div>

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

like this:

  1. <div class="validate">
  2. <a href="http://validator.w3.org/check?uri=referer">
  3. <img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0 Strict!" height="31" width="88" />
  4. </a>
  5. <a href="http://jigsaw.w3.org/css-validator/check/referer">
  6. <img src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!" height="31" width="88" />
  7. </a>
  8. <br />
  9. <br />
  10. <a href="http://www.whiteazn.com/satworld/contact/feedback.php">
  11. </a>
  12. </div>
  13. <div class="rowClear">
  14. </div>
  15. </div>
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,343
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 237
Team 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++

 
0
  #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 Quick reply to this message  
Join Date: Oct 2004
Posts: 31
Reputation: jaeSun is an unknown quantity at this point 
Solved Threads: 0
jaeSun jaeSun is offline Offline
Light Poster

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

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

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

 
0
  #7
Nov 30th, 2004
yup, that was it ..... geeeeeeeeeeeeeeeeeez stupid me
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

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

 
0
  #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 Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC