As this is a school project, I need to keep it universal. If I use flex on my home machine, all would be lost for testing by my Prof, or for use on another machine. Below is my chunk of code where Im opening the file, copying it to a new buffer, tokenizing it, and then comparing each token to a string, then converting it to a constant of the same name with the hexadecimal value of each binary opcode. Only problem right now is it throws a segmentation fault. Obviously right now I have it only checking for NOP, for testing. But Im thinking the segmentation fault is coming from using character pointers as buffers, and using strtok on those pointers? Not entirely sure though.
Code:
if((fp2 = fopen(newfile, "w+")) == NULL){
printf("file Name: %s\n", newfile);
printf("Trouble creating file..\n");
perror("error: ");
}
else
{
while(!feof(fp2))
{
strcpy(newbuffer, buffer);
tok = strtok(newbuffer, ",.-");
while(tok !=NULL)
{
while(strcmp(tok, 'NOP') != 0)
{
tok = NOP;
fputs(tok, fp2);
tok = strtok(NULL, ",.-");
}
}
fclose(fp2);
}
}