Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Session-12 CSIT 121 Spring 2006 Test-1 is on March 9 th ; Demo-5 due date extended to March 7 Test-1 is on March 9 th ; Demo-5 due date extended to March.

Similar presentations


Presentation on theme: "1 Session-12 CSIT 121 Spring 2006 Test-1 is on March 9 th ; Demo-5 due date extended to March 7 Test-1 is on March 9 th ; Demo-5 due date extended to March."— Presentation transcript:

1 1 Session-12 CSIT 121 Spring 2006 Test-1 is on March 9 th ; Demo-5 due date extended to March 7 Test-1 is on March 9 th ; Demo-5 due date extended to March 7 Revision of some topics Revision of some topics Global versus local variables Global versus local variables Using get to count total number of characters in a text file Using get to count total number of characters in a text file Accepting filename at run time Accepting filename at run time Checking for errors in file I/O Checking for errors in file I/O

2 2 Globals and Locals Any variable declared within a function is visible only within that function Any variable declared within a function is visible only within that function Let us run some sample programs provided in session 9 slides Let us run some sample programs provided in session 9 slides

3 3 Using get to count characters MS-Word has a counter that counts total characters in a file MS-Word has a counter that counts total characters in a file You can design a counter for text files that counts every character in the file You can design a counter for text files that counts every character in the file The text file is available on the lectures page (name “news.txt”). Let us design the program The text file is available on the lectures page (name “news.txt”). Let us design the program

4 4 Accepting file name at run time Let us include the following code to make the program accept file name at run time Let us include the following code to make the program accept file name at run time string filename; string filename; ifstream texty; ifstream texty; cout<<“please enter filename”; cout<<“please enter filename”; getline(cin,filename); getline(cin,filename); texty.open(filename.c_str()); texty.open(filename.c_str());

5 5 Detecting errors in opening file What type of errors are expected? What type of errors are expected? How to handle the errors? How to handle the errors? After running the open call, check if the file was really opened with the following code segment: After running the open call, check if the file was really opened with the following code segment: if (!texty) cout<<"File not found"<<endl; if (!texty) cout<<"File not found"<<endl;


Download ppt "1 Session-12 CSIT 121 Spring 2006 Test-1 is on March 9 th ; Demo-5 due date extended to March 7 Test-1 is on March 9 th ; Demo-5 due date extended to March."

Similar presentations


Ads by Google