Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Skilaverkefni 1
- //Haustönn 2015
- //Unnið af : Helen Rut Ástþórsdóttir
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <cstdlib> //Fyrir exit (1).
- using namespace std;
- string myfile ;
- // Opnar skránna sem við ætlum að vinna með.
- void OpenFile(ifstream& infile, string thefilename);
- //Telur orðinni í skránni og skilar út fjölda í heiltölu.
- int count_words (ifstream& infile, string thefilename);
- //Telur öll táknin sem skráin inniheldur og skilar okkur út fjölda í heiltölu.
- int symbols(ifstream& infile, string thefilename);
- // Telur línufjölda í skránni og skilar út heiltölu sem táknar fjölda lína.
- int count_lines (ifstream& infile, string thefilename);
- int main()
- {
- string thefilename;
- ifstream infile;
- cout << "Write the name of the file: ";
- cin >> thefilename;
- OpenFile(infile, thefilename);
- int symbols ;
- int count_words ;
- int count_lines ;
- return 0;
- }
- void OpenFile(ifstream& infile, string thefilename){
- infile.open(thefilename.c_str());
- if(infile.fail() ) {
- cout << "Can't open file: " << thefilename << endl;
- exit(1);
- }
- }
- int count_words (ifstream& thefilename)
- {
- string words_counter;
- int counter = 0;
- while (thefilename >> words_counter)
- counter = counter ++ ;
- return counter;
- }
- int symbols(ifstream& thefilename)
- {
- char x ;
- int counter = 0;
- thefilename.get(x);
- while (!thefilename.eof()) {
- thefilename.get(x);
- counter = counter + 1 ;
- }
- return counter;
- }
- int count_lines (ifstream& infile, string thefilename)
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement