diff options
author | priyanka | 2015-06-24 15:03:17 +0530 |
---|---|---|
committer | priyanka | 2015-06-24 15:03:17 +0530 |
commit | b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (patch) | |
tree | ab291cffc65280e58ac82470ba63fbcca7805165 /659/CH12/EX12.4/exm12_4.sce | |
download | Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.gz Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.bz2 Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.zip |
initial commit / add all books
Diffstat (limited to '659/CH12/EX12.4/exm12_4.sce')
-rwxr-xr-x | 659/CH12/EX12.4/exm12_4.sce | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/659/CH12/EX12.4/exm12_4.sce b/659/CH12/EX12.4/exm12_4.sce new file mode 100755 index 000000000..14262ed8e --- /dev/null +++ b/659/CH12/EX12.4/exm12_4.sce @@ -0,0 +1,38 @@ +// Example12.4 +//Write a program to illustatre error handling in file operations. + +warning('off'); +fp1=mopen('TEST','w'); //Open file in write mode,fp1 is file descriptor +for i=10:10:100 + //write data to the file + mfprintf(fp1,'%d\n',i); +end +mclose(fp1); +disp("Input file name"); +filename='a'; +while(filename~=' ') + filename=scanf("%s"); + //Error handling + try + fp2=mopen(filename,'r'); + if(fp2>0) , + break; //Terminates the loop if file exist or opened + end + + catch + //Messages to be displayed when error occured + printf("Can not open file.\n"); + printf("Type file name again.\n"); + end +end +//Code below runs while there is no error +for i=1:20 + number = mfscanf(fp2,"%d"); //Read data from file 'TEST' + if meof(fp2) then //Test for end of file + printf("Ran out of data"); + break; + else + printf("%d\n",number); //prints the data + end +end +mclose(fp2);
\ No newline at end of file |