This code is supposed to be able to test a driver or make a driver work...but so
ID: 3686352 • Letter: T
Question
This code is supposed to be able to test a driver or make a driver work...but so far I keep getting errors. How do you correct this code?
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include "fsAPI.h"
#define DEBUG
#define MAX_FILE_NAME 24
#define FILE_SOURCE "client.c"
#define FILE_SINK "newby.c"
#define DIR "CXXFILES.DIR"
void makeDOSFileName(char *, char *);
int main( int argc, char *argv[]) {
char fileName1[MAX_FILE_NAME], fileName2[MAX_FILE_NAME];
const int result = 1;
// Get parameters from command line
if(argc != 4) {
// fprintf(stderr, "Usage: fs <dir> <file_source> <file_sink> ");
// exit(1);
argv[1] = (char *) malloc(strlen(DIR)+1);
strcpy(argv[1], DIR);
argv[2] = (char *) malloc(strlen(FILE_SOURCE)+1);
strcpy(argv[2], FILE_SOURCE);
argv[3] = (char *) malloc(strlen(FILE_SINK)+1);
strcpy(argv[3], FILE_SINK);
}
// Initialize the a: floppy disk
fd_load('a'); // (There is no b: on my machine)
// Test directory listing function
printf("List the root directory ");
fd_ls();
// Test the change directory function -- first down
makeDOSFileName(argv[1], fileName1);
printf("Change the current directory to %s ", fileName1);
if(!fd_cd(fileName1)) {
fprintf(stderr, "Main: fd_cd("%s") failed ", fileName1);
}
printf("List the new current directory ");
fd_ls();
printf(" ");
// Test the change directory function -- down again
makeDOSFileName("level2.dir", fileName2);
printf("Change the current directory to %s ", fileName2);
if(!fd_cd(fileName2)) {
fprintf(stderr, "Main: fd_cd("%s") failed ", fileName2);
}
printf("List the new current directory ");
fd_ls();
printf(" ");
// Test the change directory function -- then back to root
printf("Change the current directory to root ");
if(!fd_cd("..")) {
fprintf(stderr, "Main: fd_cd("..") failed ");
}
if(!fd_cd("\")) {
fprintf(stderr, "Main: fd_cd("\") failed ");
}
printf("List the new current directory ");
fd_ls();
printf(" ");
// Test the file copy function
makeDOSFileName(argv[2], fileName1);
makeDOSFileName(argv[3], fileName2);
printf("Copy %s to %s ", fileName1, fileName2);
fd_cp(fileName1, fileName2);
printf("List the current directory ");
fd_ls();
printf(" ");
// Test the file erase function
printf("Erase %s ", fileName1);
if(!fd_rm(fileName1))
fprintf(stderr, "Main: fd_rm("%s") failed ", fileName1);
printf("List the current directory ");
fd_ls();
printf(" ");
return result;
}
void makeDOSFileName(char *rawName, char *dosName) {
int i;
assert(rawName);
assert(dosName); // This array better be big enough
i = 0;
while(rawName[i] != '') {
if(islower(rawName[i]))
dosName[i] = toupper(rawName[i]);
else
dosName[i] = rawName[i];
i++;
}
dosName[i] = '';
}
Explanation / Answer
just included the stdlib.h ,no warnings,if you have fsAPI.h ,copy that file in include folder after that you will get no errors,
the code after modification is
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include<stdlib.h>
#include <fsAPI.h>
#define DEBUG
#define MAX_FILE_NAME 24
#define FILE_SOURCE "client.c"
#define FILE_SINK "newby.c"
#define DIR "CXXFILES.DIR"
void makeDOSFileName(char *, char *);
int main( int argc, char *argv[]) {
char fileName1[MAX_FILE_NAME], fileName2[MAX_FILE_NAME];
const int result = 1;
// Get parameters from command line
if(argc != 4) {
// fprintf(stderr, "Usage: fs <dir> <file_source> <file_sink> ");
// exit(1);
argv[1] = (char *)malloc(strlen(DIR)+1);
strcpy(argv[1], DIR);
argv[2] = (char *) malloc(strlen(FILE_SOURCE)+1);
strcpy(argv[2], FILE_SOURCE);
argv[3] = (char *) malloc(strlen(FILE_SINK)+1);
strcpy(argv[3], FILE_SINK);
}
// Initialize the a: floppy disk
fd_load('a'); // (There is no b: on my machine)
// Test directory listing function
printf("List the root directory ");
fd_ls();
// Test the change directory function -- first down
makeDOSFileName(argv[1], fileName1);
printf("Change the current directory to %s ", fileName1);
if(!fd_cd(fileName1)) {
fprintf(stderr, "Main: fd_cd("%s") failed ", fileName1);
}
printf("List the new current directory ");
fd_ls();
printf(" ");
// Test the change directory function -- down again
makeDOSFileName("level2.dir", fileName2);
printf("Change the current directory to %s ", fileName2);
if(!fd_cd(fileName2)) {
fprintf(stderr, "Main: fd_cd("%s") failed ", fileName2);
}
printf("List the new current directory ");
fd_ls();
printf(" ");
// Test the change directory function -- then back to root
printf("Change the current directory to root ");
if(!fd_cd("..")) {
fprintf(stderr, "Main: fd_cd("..") failed ");
}
if(!fd_cd("\")) {
fprintf(stderr, "Main: fd_cd("\") failed ");
}
printf("List the new current directory ");
fd_ls();
printf(" ");
// Test the file copy function
makeDOSFileName(argv[2], fileName1);
makeDOSFileName(argv[3], fileName2);
printf("Copy %s to %s ", fileName1, fileName2);
fd_cp(fileName1, fileName2);
printf("List the current directory ");
fd_ls();
printf(" ");
// Test the file erase function
printf("Erase %s ", fileName1);
if(!fd_rm(fileName1))
fprintf(stderr, "Main: fd_rm("%s") failed ", fileName1);
printf("List the current directory ");
fd_ls();
printf(" ");
return result;
}
void makeDOSFileName(char *rawName, char *dosName) {
int i;
assert(rawName);
assert(dosName); // This array better be big enough
i = 0;
while(rawName[i] != '') {
if(islower(rawName[i]))
dosName[i] = toupper(rawName[i]);
else
dosName[i] = rawName[i];
i++;
}
dosName[i] = '';
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.