Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello, I was wondering if someone could help me! I am writing a program in Assembly Language and I am stuck. The memory arrays keep over flowing and I can't see where the problem might be!. The program complies fine it is when you run it that u see the problem!
/*This program will create an assembly language de-coding program to deduce results of simple calculations*/
#include <string.h>
#include <stdio.h>
#include <io.h>
#include <stdlib.h>
#include <iostream.h>
#include <conio.h>
char main_memory[99][30]={""};FILE *stream;
char msg[30]=" ";
char temp1[30]="EOF";
int i;
int count=0;
char token[6];
int count_token=1;
char Primary_String[20];
char Sub_String[20];
int j = 0;
int count_position=0;
int Sub_String_Position=0;
int String_remainder_pos=0;
int String_size;
int Integer_remainder=0;
char temp;
char Cut_Sub_String[26]="";
char Cut_String_Remainder[26]="";
char code_keys[7][7]= {""};
int t=0;
char token_code[4];
char token_value[4];void set_code_keys(void)
{
strcpy (code_keys[0],"ADR");
strcpy (code_keys[1],"LIT");
strcpy (code_keys[2],"STORE");
strcpy (code_keys[3],"ADD");
strcpy (code_keys[4],"SUB");
strcpy (code_keys[5],"MUL");
strcpy (code_keys[6],"DIV");}
void start_token(void)
{
strcpy(token,main_memory[0]);
}void get_next_token(void)
{
strcpy(token,main_memory[count_token]);
count_token++;
}void string_test(void)
{
Cut_Sub_String[20]=NULL;
Cut_String_Remainder[20]=NULL;
Sub_String_Position = 0;
count_position=0;
String_remainder_pos=0;
t=0;
strcpy(Primary_String,token);for (t=0; t<6; t++)
{
strcpy(Sub_String, code_keys[t]);String_size=strlen(Primary_String);
for (j=0; j<String_size; j++)
{if (Primary_String[j] == Sub_String[count_position])
{
Cut_Sub_String[Sub_String_Position]=Primary_String[j];}
if (Primary_String[j] != Sub_String[count_position])
{
temp=Primary_String[j];
Cut_String_Remainder[String_remainder_pos]=temp;
String_remainder_pos++;
}Sub_String_Position++;
count_position++;
}
if (strcmp(Sub_String, Cut_Sub_String)==0)
{strcpy(token_code, Cut_Sub_String);
strcpy(token_value,Cut_String_Remainder);
printf("%s", token_code);
printf("\n");
printf("%s", token_value);// printf("Match");
}
}
//Integer_remainder=atoi(Cut_String_Remainder);}
void get_info_from_file(void)
{
//Open a file for update
stream = fopen("INPUT.txt","r+");//seek to the start of the file
fseek(stream, 0, SEEK_SET);//Read a string from a file
while(strcmp(msg,"EOF\n") !=0)
{
fgets(msg,30,stream);
strcpy(main_memory[count], msg);
count++;
}//{
//printf("%s", main_memory[i]);
//}
fclose(stream);
}void main(void)
{
get_info_from_file();set_code_keys(); // Call to the set_code_keys function
start_token(); // call to the start_token function
string_test();
getch();
get_next_token();
string_test();
getch();return;
}
Emer McLysaght

Sorry to post so fast without looking at it. It seems like your arrays are too small. You may want to try getting the length of the file or whatever and sizing your arrays correctly after that.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |