Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- // -------------- By: Anisha KC | ID: 805536562---------------- //
- // ---------------- Creating the structs --------------------------- //
- // Cell struct (node)
- typedef struct cell {
- char *data;
- struct cell *left;
- struct cell *right;
- } cell;
- // Moving commands struct (state machines)
- typedef struct stateMachine {
- int currentState;
- char readVal;
- char writeVal;
- char moveDirection;
- int newState;
- } stateMachine;
- // ----------------- Done creating structs ------------------------- //
- // ----------------------------- Main function ------------------------------ //
- int main() {
- // Variables
- char *pInitialTape, initialTape[50];pInitialTape = initialTape;
- int *pNumOfStates, numOfStates; pNumOfStates = &numOfStates;
- int *pStartState, startState; pStartState = &startState;
- int *pEndState, endState; pEndState = &endState;
- // Ask for input file
- FILE *fp;
- char fileName [500];
- printf("Input file path: ");
- scanf("%s", &fileName);
- // Open the input file
- fp = fopen(fileName,"r");
- // File is not found
- if(fp == NULL) {
- printf("File not found \n");
- return (1);
- }
- // Read the file
- // Get initial tape, number of states, start state and end state
- fscanf(fp, "%s \n %d \n %d \n %d \n", pInitialTape, &pNumOfStates, &pStartState, &pEndState);
- cell start = {"A", NULL, NULL};
- printf("Initial tape: %s, # of States: %d, Start State: %d, End State: %d \n", pInitialTape, pNumOfStates, pStartState, pEndState);
- // Read rest of the file and get state machines (if any)
- char * line = NULL;
- size_t len = 0;
- ssize_t read;
- stateMachine *pTempSM, tempSM;
- pTempSM = &tempSM;
- while ((read = getline(&line, &len, fp)) != -1) {
- fscanf(fp, "(%d,%c)->(%c,%c,%d", &pTempSM->currentState, &pTempSM->readVal, &pTempSM->writeVal, &pTempSM->moveDirection, &pTempSM->newState);
- printf("(%d,%c)->(%c,%c,%d)\n",pTempSM->currentState, pTempSM->readVal, pTempSM->writeVal, pTempSM->moveDirection, pTempSM->newState);
- }
- // Closing the file
- fclose(fp);
- return 0;
- }
- // ----------------------------- End of main function ------------------------------ //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement