Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 18th, 2010 | Syntax: None | Size: 1.58 KB | Hits: 32 | Expires: Never
Copy text to clipboard
  1. #include<iostream>
  2. #include<string>
  3. #include<fstream>
  4. #include<iomanip>
  5.  
  6. using namespace std;
  7.  
  8. string readLine(istream& fin)
  9. {
  10. char buff[256];
  11.  
  12. // Clear any remaining end of line characters
  13. if(fin.peek()=='\n')
  14. {
  15. fin.ignore();
  16. }
  17.  
  18. // Read the line into a buffer
  19. fin.getline(buff, 256, '\n');
  20.  
  21. // Convert the buffer to a string and return it
  22. return string(buff);
  23. }
  24.  
  25. void main()
  26. {
  27. //variables
  28. char ch;
  29. int letters = 0;
  30. int wordcount =0;
  31. //input of words
  32. //conversion of text file
  33. //removal of capitals and punct
  34. //struct
  35.  
  36.  
  37. //word length count [12]
  38. //
  39. int wordlengthcount[12];
  40. string word;
  41. bool eofReached = false;
  42. string fName = "initialattempt.txt";
  43. string fName2 = "converted.ptx";
  44.  
  45. ifstream inFile(fName.c_str());
  46. ofstream outFile("converted.ptx");
  47. if(!inFile)
  48. {
  49. // If file is not read: Show error message
  50. cout << "Error, can't open file" << endl;
  51. }
  52. else
  53. {
  54. // If file is read: Continue
  55. while(!inFile.eof())
  56. {
  57. inFile >> word;
  58. for(int i = 0; i < (int)word.length(); i++)
  59. {
  60. word[i] = tolower(word[i]);
  61. if(ispunct (word[i]))
  62. {
  63. word[i] = ' ';
  64. }
  65.  
  66.  
  67. }
  68.  
  69. outFile << word << endl;
  70. eofReached = inFile.eof();
  71. }
  72.  
  73. inFile.close();
  74. outFile.close();
  75.  
  76. }
  77. ifstream ptxFile(fName2.c_str());
  78.  
  79. if(!ptxFile)
  80. { //////////////////////////////////////////////
  81. /// If file is not read: Show error message///
  82. //////////////////////////////////////////////
  83. cout << "Error, can't open file" << endl;
  84. }
  85. else
  86. {
  87. while(!ptxFile.eof())
  88. {
  89. ptxFile>>word;
  90.  
  91. if(word.length()>12)
  92. {
  93. wordlengthcount[12]++;
  94. }
  95. else
  96. {
  97. wordlengthcount[word.length()-1]++;
  98. }
  99. }
  100.  
  101. }