add inputted filename format checking
This commit is contained in:
parent
61f6fc9506
commit
fa17a7fda3
@ -1,7 +1,22 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
void writeBinaryFile(word instrs[], char outputFile[]){
|
bool isValidFileFormat(char filename[], char expectedExtension[]){
|
||||||
|
int *pointLoc = strrchr(filename, '.');
|
||||||
|
|
||||||
|
if(pointLoc != NULL){
|
||||||
|
if(strcmp(pointLoc, expectedExtension)==0){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int writeBinaryFile(word instrs[], char outputFile[]){
|
||||||
|
|
||||||
|
if (!isValidFileFormat(filename, "bin")){
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
@ -9,6 +24,9 @@ void writeBinaryFile(word instrs[], char outputFile[]){
|
|||||||
fwrite(instrs, 4, sizeof(instrs), fp);
|
fwrite(instrs, 4, sizeof(instrs), fp);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void readAssemblyFile()
|
int readAssemblyFile() {
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user