944,008 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 5531
  • C++ RSS
Nov 30th, 2004
0

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

Expand Post »
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?

C++ Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 12
Solved Threads: 0
Light Poster
jaeSun is offline Offline
31 posts
since Oct 2004
Nov 30th, 2004
0

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

You're not using an input function that skips whitespace (which includes newlines), are you?
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Nov 30th, 2004
0

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

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

C++ Syntax (Toggle Plain Text)
  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)

C++ Syntax (Toggle Plain Text)
  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:

C++ Syntax (Toggle Plain Text)
  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
Reputation Points: 12
Solved Threads: 0
Light Poster
jaeSun is offline Offline
31 posts
since Oct 2004
Nov 30th, 2004
0

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

also, here is part of the output:

C++ Syntax (Toggle Plain Text)
  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:

C++ Syntax (Toggle Plain Text)
  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>
Reputation Points: 12
Solved Threads: 0
Light Poster
jaeSun is offline Offline
31 posts
since Oct 2004
Nov 30th, 2004
0

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

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.
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Nov 30th, 2004
0

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

hmm, i never thought of that ... ill go try that out ... stupid me ..
Reputation Points: 12
Solved Threads: 0
Light Poster
jaeSun is offline Offline
31 posts
since Oct 2004
Nov 30th, 2004
0

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

yup, that was it ..... geeeeeeeeeeeeeeeeeez stupid me
Reputation Points: 12
Solved Threads: 0
Light Poster
jaeSun is offline Offline
31 posts
since Oct 2004
Dec 1st, 2004
0

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

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?
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Problem with validation in c
Next Thread in C++ Forum Timeline: Can Someone Tell me why my program does not run





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC