Advertisement
helenrut

Untitled

Sep 11th, 2015
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 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& thefilename);
  18.  
  19. //Telur öll táknin sem skráin inniheldur og skilar okkur út fjölda í heiltölu.
  20. int symbols(ifstream& 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& 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.  
  43.  
  44. return 0;
  45. }
  46.  
  47.  
  48.  
  49. void OpenFile(ifstream& infile, string thefilename){
  50. infile.open(thefilename.c_str());
  51.  
  52. if(infile.fail() ) {
  53. cout << "Can't open file: " << thefilename << endl;
  54. exit(1);
  55. }
  56. }
  57.  
  58.  
  59. int count_words (ifstream& thefilename)
  60. {
  61.  
  62. string words_counter;
  63. int counter = 0;
  64. while (thefilename >> words_counter)
  65. counter = counter ++ ;
  66.  
  67. return counter;
  68.  
  69. }
  70.  
  71. int symbols(ifstream& thefilename)
  72. {
  73. char x ;
  74.  
  75. int counter = 0;
  76. thefilename.get(x);
  77.  
  78. while (!thefilename.eof()) {
  79.  
  80. thefilename.get(x);
  81. counter = counter + 1 ;
  82.  
  83. }
  84. return counter;
  85. }
  86.  
  87. int count_lines (ifstream& thefilename)
  88. {
  89. char (y);
  90. int counter = 0 ;
  91.  
  92. while (!thefilename.eof()) {
  93. thefilename.get(y);
  94. if (y == '\n'){
  95. counter = counter ++ ;
  96. }
  97.  
  98. }
  99. if y! = '\n'{
  100. counter = counter ++ ;
  101. }
  102.  
  103. return 0;
  104.  
  105. }
  106.  
  107. void print_out (ifstream& thefilename)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement