fix syntax errors in fileio.c
This commit is contained in:
parent
647f47e39d
commit
62ff6e9e02
@ -1,8 +1,8 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "parser.c"
|
#include "parser.c"
|
||||||
|
#include "fileio.c"
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
20
src/fileio.c
20
src/fileio.c
@ -4,7 +4,7 @@
|
|||||||
#define MAX_ASM_LINE_LENGTH 30
|
#define MAX_ASM_LINE_LENGTH 30
|
||||||
|
|
||||||
int isValidFileFormat(char filename[], char expectedExtension[]){
|
int isValidFileFormat(char filename[], char expectedExtension[]){
|
||||||
int *pointLoc = strrchr(filename, '.');
|
char *pointLoc = strrchr(filename, '.');
|
||||||
|
|
||||||
if(pointLoc != NULL){
|
if(pointLoc != NULL){
|
||||||
if(strcmp(pointLoc, expectedExtension)==0){
|
if(strcmp(pointLoc, expectedExtension)==0){
|
||||||
@ -14,9 +14,9 @@ int isValidFileFormat(char filename[], char expectedExtension[]){
|
|||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int writeBinaryFile(word instrs[], char outputFile[]){
|
int writeBinaryFile(word instrs[], char outputFile[], int numInstrs){
|
||||||
|
|
||||||
if (!isValidFileFormat(filename, "bin")){
|
if (!isValidFileFormat(outputFile, "bin")){
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,14 +28,14 @@ int writeBinaryFile(word instrs[], char outputFile[]){
|
|||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fwrite(instrs, 4, sizeof(instrs), fp);
|
fwrite(instrs, 4, sizeof(word) * numInstrs, fp);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
char **readAssemblyFile(char inputFile[]) {
|
char **readAssemblyFile(char inputFile[]) {
|
||||||
if (!isValidFileFormat(filename, "s")){
|
if (!isValidFileFormat(inputFile, "s")){
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,24 +51,24 @@ char **readAssemblyFile(char inputFile[]) {
|
|||||||
{
|
{
|
||||||
if (ch == '\n' || ch == '\0')
|
if (ch == '\n' || ch == '\0')
|
||||||
{
|
{
|
||||||
count++;
|
lineCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char **heap = malloc(sizeof(char *) * count);
|
char **heap = malloc(sizeof(char *) * lineCount);
|
||||||
|
|
||||||
rewind(fp);
|
rewind(fp);
|
||||||
|
|
||||||
for( int i=0; i<count; i++) {
|
for( int i=0; i<lineCount; i++) {
|
||||||
|
|
||||||
char tmp[512];
|
char tmp[512];
|
||||||
|
|
||||||
// read line into tmp
|
// read line into tmp
|
||||||
fgets(tmp, MAX_ASM_LINE_LENGTH-1, fp);
|
fgets(tmp, MAX_ASM_LINE_LENGTH-1, fp);
|
||||||
|
|
||||||
size = strlen(tmp)
|
int size = strlen(tmp);
|
||||||
|
|
||||||
char *line = malloc(size+1) // allocate mem for text line
|
char *line = malloc(size+1); // allocate mem for text line
|
||||||
|
|
||||||
strcpy(line, tmp);
|
strcpy(line, tmp);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user