Advertisement
helenrut

Untitled

Sep 11th, 2015
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. //Skilaverkefni 1
  2. //Haustönn 2015
  3. //Unnið af : Helen Rut Ástþórsdóttir
  4.  
  5. #include <iostream>
  6. #include <fstream>
  7. #include <string>
  8. #include <cstdlib> //Fyrir exit (1).
  9.  
  10. using namespace std;
  11.  
  12. string myfile ;
  13. // Opnar skránna sem við ætlum að vinna með.
  14. void OpenFile(ifstream& infile, string thefilename);
  15.  
  16. //Telur orðinni í skránni og skilar út fjölda í heiltölu.
  17. int count_words (ifstream& infile, string thefilename);
  18.  
  19. //Telur öll táknin sem skráin inniheldur og skilar okkur út fjölda í heiltölu.
  20. int symbols(ifstream& infile, string thefilename);
  21.  
  22. // Telur línufjölda í skránni og skilar út heiltölu sem táknar fjölda lína.
  23. int count_lines (ifstream& infile, string thefilename);
  24.  
  25.  
  26.  
  27. int main()
  28. {
  29.  
  30. string thefilename;
  31. ifstream infile;
  32.  
  33. cout << "Write the name of the file: ";
  34. cin >> thefilename;
  35. OpenFile(infile, thefilename);
  36.  
  37. int symbols ;
  38. int count_words ;
  39. int count_lines ;
  40.  
  41.  
  42. return 0;
  43. }
  44.  
  45.  
  46.  
  47. void OpenFile(ifstream& infile, string thefilename){
  48. infile.open(thefilename.c_str());
  49.  
  50. if(infile.fail() ) {
  51. cout << "Can't open file: " << thefilename << endl;
  52. exit(1);
  53. }
  54. }
  55.  
  56.  
  57. int count_words (ifstream& thefilename)
  58. {
  59.  
  60. string words_counter;
  61. int counter = 0;
  62. while (thefilename >> words_counter)
  63. counter = counter ++ ;
  64.  
  65. return counter;
  66.  
  67. }
  68.  
  69. int symbols(ifstream& thefilename)
  70. {
  71. char x ;
  72.  
  73. int counter = 0;
  74. thefilename.get(x);
  75.  
  76. while (!thefilename.eof()) {
  77.  
  78. thefilename.get(x);
  79. counter = counter + 1 ;
  80.  
  81. }
  82. return counter;
  83. }
  84.  
  85. int count_lines (ifstream& infile, string thefilename)
  86. {
  87.  
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement