Search Results

Search found 1 results on 1 pages for 'user1691766'.

Page 1/1 | 1 

  • Reading a text file, and performing actions based on strings read

    - by user1691766
    Let me start off by saying that I really am quite new to C. So basically I have a text file (contains around 30 assembly instructions, separated by new lines), and I am successfully reading them into my program. From here I need to perform certain actions based off each instruction. I would assume the best way to do this would be via a switch-case statement. However I am encountering a lot of problems due to me trying to compare strings that are 33 characters long. Can anyone please offer me advice on what I am doing wrong, or offer an alternative? Thanks in advance. Here is what I have so far: char instruction[29][ 33 ]; int i,run; i = 0; run = 1; FILE *instPtr; /* LOADING INSTRUCTIONS FROM FILE INTO "instruction" ARRAY*/ if ( ( instPtr = fopen("MIPSinstructions.txt", "r") ) == NULL ) { printf("File could not be opened\n"); } // end if else { fscanf( instPtr, "%s", instruction[0]); printf("%s\n", instruction[0]); while (!feof( instPtr ) ){ i++; fscanf( instPtr, "%s", instruction[i]); printf("%s\n", instruction[i]); } fclose( instPtr ); i = 0; // Reset the counter } //end else return 0; }

    Read the article

1