LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   C source file Parse error before 38 (https://www.linuxquestions.org/questions/programming-9/c-source-file-parse-error-before-38-a-364634/)

exvor 09-18-2005 05:16 PM

C source file Parse error before 38
 
Code:

#include<stdio.h>
#include<stdlib.h>
#define SIZE 100

int prog_enterd(int *,int);

int main()
{
  int memory[SIZE];  //simulated memory 
  int mess;
  int acc = 0;
  int intructcounter;
  int operationcode,operand;
  int instruction;
  int loop;
  //print welcome message first
  printf("\n\n");
 
  printf("***Welcome to Simcom!***\n***Please enter your program one
instruction word at a time**\n***I will type the location number and a
question mark***\n***You then type the word for that
location***\n***Type the sentinal -99999 to stop entering your
program***\n");
  mess = prog_enterd(memory,SIZE);
  if ( mess == 0)
        {
          printf("You have run out of lines to enter programs or you are at the
 end of memory\n");
          exit (0);
        }

       
  else
    { printf("Great Program loading compleated\n");
    }
  printf("Program execution begins\n");
 
 for (intructcounter =0; intructcounter != 43 && intructcounter
< 99  intructcounter++)

      {
        instruction = memory[intructcounter];
        operationcode = instruction / 100;
        operand = instruction % 100;
       
        switch (operationcode)
        {
        case 10:    scanf("%d", &memory[operand]); //read
        break;
       
        case 20:    acc = memory[operand]; //load
        break;
       
        case 30:    acc += memory[operand]; //add
        break;
       
        case 43:    printf("Simcom exectution terminated\n"); //HALT
        break;
       
        case 11:    printf("%d\n",memory[operand]; //write
        break;
       
        case 21:    memory[operand] = acc; //store
        break;
       
        case 31:    acc -= memory[operand]; //subtract
        break;
       
        case 32:    acc /= memory[operand]; //devide
        break;

        case 33:    acc *= memory[operand]; //multiply
        break;
 
        case 40:  intructcounter = operand;
        break;
 
        case 41:  if (acc < 0) intructcounter = operand;
        break;
       
            case 42:  if (acc == 0) intructcounter = operand;
        break;
       
    }
   
   
}
printf("Program execution compleate\n");

printf("Memory dump information");

for (loop = 0; loop <= mess; loop++)
    printf("%02d  %04d%c",loop,memory[loop],(loop % 4 == 0) ? '/n' : ' ');

return 0; 


}

int prog_enterd(int *mem, int size)
{
    int count = 0;

    do
    {
       
        printf("%02d ? ",count);
        scanf("%d",&mem[count]);
        printf("\n");
        if (mem[count] == -99999)
            return count - 1;
        count++;
    }
    while (count < size);
    return 0;

}

strange issue here it says i have a parse error before line 38 ((its in blue))
but i dont see it do any of you see it?

acid_kewpie 09-18-2005 05:24 PM

well on line 38 you are missing a ; between 99 and intructcounter++

exvor 09-18-2005 05:27 PM

Woops let me check source to make sure thats not in the real source

bulliver 09-18-2005 05:51 PM

Also:
Code:

printf("%02d  %04d%c",loop,memory[loop],(loop % 4 == 0) ? '/n' : ' ');
should be:
Code:

printf("%02d  %04d%c",loop,memory[loop],(loop % 4 == 0) ? '\n' : ' ');
With acid's change and mine, the proggy is compiling for me...

Dark_Helmet 09-18-2005 05:55 PM

There's one more, but it's only a warning:
Code:

for (loop = 0; loop <= mess; loop++)
    printf("%02d  %04d%c",loop,memory[loop],(loop % 4 == 0) ? '/n' : ' ');

That's a multi-character, character constant. I assume you intended '\n'

exvor 09-19-2005 02:10 PM

Yea I made both changes and now it compiles ok just doesent work as intended.

for some reason my transfer of control doesnt go where intened and the loop doesent stop looping

tho these are issues that i need to solve thanks everyone


All times are GMT -5. The time now is 05:04 AM.