a) Compare and contrast systems programming in Windows as against systems programming in Unix/Linux.
b) Explain the term structured exception handling (SEH) as used in systems programming and give a practical example of how it can be used to handle errors in a block of code.
c) Write a C/C++ system program to delete an unwanted file in the Windows file system. Compile and run the program and copy the source code into your answer booklet.
Windows Linux
CR 8. Structured exception handling enables you to have complete control over the handling of exceptions, provides support for debuggers, and is usable across all programming languages and machines. Vectored exception handling is an extension to structured exception handling.
#include <string.h>
#include <stdio.h>
#include<windows.h>
void foo (FILE * fileDescr)
{
char c[12];
long lSize;
int mySecretNumber;
fseek (fileDescr , 0 , SEEK_END);
lSize = ftell (fileDescr);
rewind (fileDescr);
fread(c, 1, lSize, fileDescr);
mySecretNumber = atoi(c);
__try
{
mySecretNumber = mySecretNumber / mySecretNumber;
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
printf("In the exception handler");
}
}
int main (int argc, char **argv)
{
FILE * fileDescr = NULL;
if(fileDescr = fopen(argv[1], "r"))
{
foo(fileDescr);
fclose(fileDescr);
}
}
CR 10.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int status;
char fname[20];
cout<<"Enter name of file, you want to delete : ";
gets(fname);
status=remove(fname);
if(status==0)
{
cout<<"file "<<fname<<" deleted successfully..!!\n";
}
else
{
cout<<"Unable to delete file "<<fname<<"\n";
perror("Error Message ");
}
getch();
}
Comments
Leave a comment