![]() |
| | #1 |
| Registered User Join Date: May 2004
Posts: 6
| Code: #include <stdio.h>
#include <stdlib.h>
#include "memory.h"
#include "processor.h"
void read(int address)
{
int data = 0;
printf("Please input the data: \n");
perror("Please input the data: ");
scanf("%d", &data);
writeMemory(address,data);
}
Code: #include <stdio.h>
#include "memory.h"
#include "processor.h"
#include "Instructions.h"
int main()
{
char * fileName = "data.txt";
int flag = loadFile( fileName );
if ( flag > 0 )
execute();
return 0;
}
int loadFile( char * fileName )
{
FILE * fPointer;
int line = 0;
int data = 0;
fPointer = fopen( fileName, "r" );
if ( fPointer == NULL )
{
perror( "File could not be opened\n" );
return -1;
}
else
{
while ( fscanf( fPointer, "%d", & data ) == 1 )
{
writeMemory( line, data );
++line;
}
fclose(fPointer);
return 1;
}
}
void execute( void )
{
int instructionRegister = 0;
int instruction = 0;
int operand = 0;
terminator = 0;
accumulator = 0;
instructionCounter = 0;
while ( instructionCounter < SIZE && terminator==0)
{
instructionRegister = readMemory( instructionCounter );
++instructionCounter;
instruction = instructionRegister / 100;
operand = instructionRegister % 100;
switch ( instruction )
{
case READ:
read( operand );
break; default:
terminator = 1;
break;
}
}
}
Code: Please input the data: : Error 0 23 Please input the data: : Error 0 54 Please input the data: Please input the data: The output is:77 ***** Simpletron execution terminated ***** |
| robert_sun is offline | |
| | #3 |
| Registered User Join Date: May 2004
Posts: 6
| nop, still doesn't work. Only the the perror() was called and error message printed out before the user input, the printf() still doesn't work properly |
| robert_sun is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Global Variables | Taka | C Programming | 34 | 11-02-2007 03:25 AM |
| MFC Message Map Problem | durban | C++ Programming | 10 | 10-31-2005 01:55 PM |
| problem printing with floating number | ssharish | C++ Programming | 4 | 01-25-2005 07:31 PM |
| problem with UDP WSAAsyncSelect socket, no callback message received??? | hanhao | Networking/Device Communication | 1 | 03-29-2004 11:59 AM |
| Printing problem using CDC::StartDoc() | LuckY | Windows Programming | 0 | 01-20-2003 04:48 PM |