Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Implement a File System in C++, which would provide following API functions: FIL

ID: 3806893 • Letter: I

Question

Implement a File System in C++, which would provide following API functions:

FILE* x_fopen(const char *filename, const char *mode);

Functionality and parameter list like in fopen() function. MSDN: http://msdn.microsoft.com/en-us/library/yeby3zcb.aspx

• Instead of pointer to FILE, your function should return pointer to OSFILE – a RAM structure which you designed in Part 2 for the management of a file. OSFILE should be used in all other functions instead of FILE when relevant.

• File names supported: character string 1 to 64 character long

• Only “rb”, “wb”, “w+b”, “ab” should be supported

int x_fclose(OSFILE *stream);

Function Description x_fopen

FILE* x_fopen(const char *filename, const char *mode);

Functionality and parameter list like in fopen() function. MSDN: http://msdn.microsoft.com/en-us/library/yeby3zcb.aspx

• Instead of pointer to FILE, your function should return pointer to OSFILE – a RAM structure which you designed in Part 2 for the management of a file. OSFILE should be used in all other functions instead of FILE when relevant.

• File names supported: character string 1 to 64 character long

• Only “rb”, “wb”, “w+b”, “ab” should be supported

x_fclose

int x_fclose(OSFILE *stream);

x_fread int x_fread(void *buffer, size_t nBytes, OSFILE*stream); x_fwrite int x_fwrite(void *buffer, size_t nBytes, 0SFILE*stream); x_fseek int x_fseek(OSFILE *stream, long offset, int origin); x_ftell long x_ftell(OSFILE *stream); x_remove int x_remove(const char *path);

Explanation / Answer

Based on the functions I have the code below

********x_fopen**********

Output: we are in 2013

********x_fclose************

Output: This is chegg.com

*****************

*************fread***************

**************************

********fwrite***************

**************fseek***************

******************************ftell**************

output:This is chegg.com

Total size of the file.tzt file is 17 bytes

***************fremove*************

****************

Output: File deleted Successfully

P.S All the above code writtren are withe respect to the syntax asked in the problem statement.

  #include <stdio.h>  #include <stdlib.h>    int main () {    FILE * pFile;    long lSize;    char * buffer;    size_t result;      pFile = fopen ( "myfile.bin" , "rb" );    if (pFile==NULL) {fputs ("File error",stderr); exit (1);}      // obtain file size:    fseek (pFile , 0 , SEEK_END);    lSize = ftell (pFile);    rewind (pFile);      // allocate memory to contain the whole file:    buffer = (char*) malloc (sizeof(char)*lSize);    if (buffer == NULL) {fputs ("Memory error",stderr); exit (2);}      // copy the file into the buffer:    result = fread (buffer,1,lSize,pFile);    if (result != lSize) {fputs ("Reading error",stderr); exit (3);}      /* the whole file is now loaded in the memory buffer. */      // terminate    fclose (pFile);    free (buffer);    return 0;  }  
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote