Answer to Question #168007 in C++ for Jean Claude

Question #168007

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. 


1
Expert's answer
2021-03-03T08:02:36-0500

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();

}


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS